Gaia/System/NewModule: Difference between revisions
(Created page with "If you want to add a new functionality, a.k.a., a new script or a new module into system app after bug 1094759, please read this. == If you want to use BaseModule == Great! I...") |
No edit summary |
||
Line 4: | Line 4: | ||
== If you want to use BaseModule == | == If you want to use BaseModule == | ||
Great! It's providing a promise based start procedure and what you need to do. | Great! It's providing a promise based start procedure and what you need to do. | ||
var NewModule = function() {}; | var NewModule = function() {}; | ||
BaseModule.create(NewModule, { | BaseModule.create(NewModule, { | ||
name: 'NewModule', | |||
_start: function() { | |||
// return a promise if your start progress involves some asynchronous operation | |||
// return null or do not return, then we will unblock your module from the starting process right away once | |||
// yourModule.start() is called | |||
// BaseModule has a native start() function to process not only your own starting (this._start()) but also the child | |||
// module's start() function. The whole starting process will be resolved only when all the children's start process | |||
// is resolved. | |||
} | |||
}); | }); | ||
== If you don't want to use BaseModule == | == If you don't want to use BaseModule == | ||
It's okay. But you have to provide this interface for us: | It's okay. But you have to provide this interface for us: | ||
var NewModule = { | |||
var NewModule = { | start: function() { | ||
// return a promise if your start progress involves some asynchronous operation | |||
// return null or do not return, then we will unblock your module from the starting process right away once | |||
// yourModule.start() is called | |||
} | |||
}; | |||
}; | |||
== No matter what you choose to go == | == No matter what you choose to go == |
Revision as of 06:26, 13 May 2015
If you want to add a new functionality, a.k.a., a new script or a new module into system app after bug 1094759, please read this.
If you want to use BaseModule
Great! It's providing a promise based start procedure and what you need to do.
var NewModule = function() {}; BaseModule.create(NewModule, { name: 'NewModule', _start: function() { // return a promise if your start progress involves some asynchronous operation // return null or do not return, then we will unblock your module from the starting process right away once // yourModule.start() is called // BaseModule has a native start() function to process not only your own starting (this._start()) but also the child // module's start() function. The whole starting process will be resolved only when all the children's start process // is resolved. } });
If you don't want to use BaseModule
It's okay. But you have to provide this interface for us:
var NewModule = { start: function() { // return a promise if your start progress involves some asynchronous operation // return null or do not return, then we will unblock your module from the starting process right away once // yourModule.start() is called } };
No matter what you choose to go
Don't put your new script in the header of system app. If it's necessary to go alive when booting, please find a proper parent module and lazy load it. If you are using BaseModule, 1. Put the module in the parent module's SUB_MODULES if you think it's blocking the starting progress of the parent module. 2. If the new module is not as important to block the parent, use this.loadWhenIdle([NEW_MODULE]) in parent's start function 3. If the new module is only serving some on demand request, consider to lazy load the new module in the parent module's event handler and start it.