jfactory
1.0.0
アプリケーションをキャンセル可能なコンポーネントに簡単にモジュール化します。
彼らが初期化するものはすべて、監視、停止、自動的に削除することができます。
ビュー、ネストされた約束、リクエスト、リスナー、DOMおよびCSSを含む。
install 、 enable 、 disable 、およびuninstallます。await installとawait enableの際に、保留中のサブスクリプションを自動的に待ちます、すべてがタスクに並行しています。uninstallリバートinstall 、Reverts enable disable 。| インストール | ドキュメント |
|---|---|
npm add jfactory | 特性 /クラス |
コンポーネントは、任意のクラスから拡張することができます。より単純に、ショートカット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 ( ) ;