sword-framework

A front-end framework for rapid development like a sword

Usage no npm install needed!

<script type="module">
  import swordFramework from 'https://cdn.skypack.dev/sword-framework';
</script>

README

Sword

A front-end framework for rapid development like a sword

Install

With Zip compressed file
With npm: $: npm install sword-framework
With yarn: $: yarn add sword-framework

Usage

Definition Module

Prototype: Sword.prototype.define(moduleName, definer)

Example

sword.define("dog", (exports) => {
    exports({
        say: () => { console.log("Wang!") },
        eat: () => { console.log("I'm eating...") }
    });
});

Load Module & Use Module

Prototype: Sword.prototype.use(moduleNames, cb) Tips: Parameter 'cb' called when all modules are loaded. Do not use the module you want to load outside the callback function CB of use function, because at that time we are not sure if the module is loaded at this time.

Example

sword.use([ "dog" ], () => {
    sword.dog.say();
    sword.dog.eat();
});
sword.dog.say();// Wrong, Because the module has not been loaded yet

Load Module & Use Module By Promise

Prototype: Sword.prototype.useSync(moduleNames) Do not use a module outside the Promise. prototype. then method because we cannot guarantee that the module has been loaded (except await) when used.

Example 1

sword.use([ "dog" ]).then(() => {
    sword.dog.say();
    sword.dog.eat();
});
sword.dog.say();// Wrong, Because the module has not been loaded yet

Example 2

(async function() {})(
    (await sword.use([ "dog" ]));
    sword.dog.say();
    sword.dog.eat();
);

Modules