jfactory
1.0.0
ปรับเปลี่ยนแอปพลิเคชันของคุณให้เป็นส่วนประกอบที่ยกเลิกได้อย่างง่ายดาย
ทุกสิ่งที่พวกเขาเริ่มต้นสามารถตรวจสอบหยุดและลบออกโดยอัตโนมัติ
รวมถึงมุมมองคำสัญญาที่ซ้อนกันคำขอผู้ฟัง DOM และ CSS
install แบบอะซิงโครนัส enable disable และ uninstallawait 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 ( ) ;