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