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 ( ) ;