jfactory
1.0.0
輕鬆將您的應用程序模塊化為可取消的組件。
他們初始化的所有內容都可以自動監視,停止和刪除,
包括視圖,嵌套承諾,請求,聽眾,DOM和CSS。
install , enable , disable和uninstall功能。await install和await enable時,會自動等待等待訂閱,所有內容都同時將其平行於任務中。uninstall恢復install , disable恢復enable 。| 安裝 | 文件 |
|---|---|
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 ( ) ;