jFactory is an Open Source JavaScript library that allows you to easily compartmentalize your application into components. Thus, everything they initialize can be monitored, stopped and removed automatically.
Why? Imagine a feature in your application that uses views, css, event listeners, requests and asynchronous processes. jFactory groups all this together into a component object that provides the methods $install(), $enable(), $disable() and $uninstall()
. Now, you can safely stop, remove or restart the component, making your asynchronous application easier to control and clean.
jFactory components are able to:
<template>
jFactory also supports Vue.js, React, and HTML5 WebComponents allowing components to automatically uninstall and reinstall their views. See Playground.
In a nutshell, jFactory provides methods to register listeners, views, dom, css, requests and asynchronous tasks that will be automatically stopped (including subpromise trees) and removed at opposite service state change (install/uninstall, enable/disable).
Components can be created from any Class, or by using a simple Object Literal through the shortcut jFactory()
:
let component = jFactory("myComponent", {
onInstall() {
this.$domFetch("#myDiv", "asset.html", "#parent").then(() => this.$log("html loaded"));
},
onEnable() {
this.$interval("myUpdater", 250, () =>
this.$fetchJSON("myRequest", "asset.json").then(() => this.$log("updated"))
)
}
// ... your own methods and properties
})
await component.$install();
await component.$enable();
await component.$disable();
await component.$uninstall();
jFactory is an easy-to-learn library based on jQuery. Unlike a framework, it does not impose an application architecture: you are free to use only what you want without restriction.
All the methods are listed here.
See also the Playground and the Starter Kit
Registry: all component subscriptions (listeners, promises, timers, fetch, dom…) are explorable in a registry, allowing quick visual inspections in DevTools.
Tasks: asynchronous processes can be registered as expirable tasks that block the current Service State Change, guaranteeing that everything is resolved before completing it, including all subpromises.
Remove Phase: jFactory will automatically stop and remove the subscriptions (listeners, promises, timers, fetch, dom…) registered during an opposite state change (install/uninstall, enable/disable)
Promise Chains: jFactory uses extended native Promises that makes the whole Chain Awaitable, Completable, Cancelable and Expirable.
Traits: Components are Objects created from Classes dynamically extended by JFactoryTraits.
Debug: jFactory is designed for asynchronous component-based application development, using contextual loggers and subloggers, filterable mapped stack traces, identifiers, loggable extended errors, explorable promise chains, …
jFactory is designed from ES6 Classes:
####### Modular JavaScript
jFactory is an Open Source project. Your comments, bug reports and code proposals are always welcome. This project is new and you can help a lot by spreading the word. Also consider adding a github star, as it seems very important for its visibility at this stage. Thank you for your contributions!
Author: jfactory-es
Source Code: https://github.com/jfactory-es/jfactory
#javascript