jfactory
1.0.0
Easily modularize your application into cancelable components.
Everything they initialize can be monitored, stopped and removed automatically,
including views, nested promises, requests, listeners, DOM and CSS.
install, enable, disable, and uninstall functionality.await install and await enable, everything is parallelized into tasks.uninstall reverts install, disable reverts enable.| Installation | Documentation |
|---|---|
npm add jfactory |
Traits / Classes |
Components can be extended from any Class,
or more simply by using an Object literal through the shortcut jFactory():
let component = jFactory("myComponent", {
async onInstall() {
this.$domFetch("myDom", "asset.html", "body");
this.$cssFetch("myCss", "asset.css");
},
async onEnable() {
this.$interval("myUpdater", 1000, () =>
this.$fetchJSON("myRequest", "asset.json")
.then(data => this.$log("updated", data))
);
this.$on("click", "#bt-switch", () => this.mySwitchHandler());
this.$on("click", "#bt-close", () => this.myCloseHandler());
},
async mySwitchHandler() {
await (this.$.states.enabled ? this.$disable() : this.$enable());
this.$log(this.$.states.enabled);
},
async myCloseHandler() {
// Called by the click event on #bt-close
// Everything in the component registery is automatically stoped and removed:
// (myDom, myCss, myUpdater, myRequest, DOM events)
// Residual callbacks not manually stopped from
// the onDisable() and onUninstall() handlers will be ignored.
await this.$uninstall();
}
})
await component.$install();
await component.$enable();