Confirmed users
478
edits
No edit summary |
|||
Line 5: | Line 5: | ||
== Target == | == Target == | ||
The main purposes/targets are: | The main purposes/targets are: | ||
# | # Minimize the memory usage of the system app | ||
# More maintainable and testable | # More maintainable and testable | ||
# Easier for a new contributor to jump in | # Easier for a new contributor to jump in | ||
Line 12: | Line 12: | ||
== Stages == | == Stages == | ||
=== Stage.1 - Painless instantiation === | === Stage.1 - Painless instantiation === | ||
Rewrite all modules to be instantiable and rewrite unit tests, as well as jsdoc. | |||
Rewrite all modules to be instantiable and rewrite unit tests, as well as jsdoc. '''Everything that has states need to be an instance, even if we only need one in the app.''' | |||
The stage’s target is to make sure we could have the following pattern: | The stage’s target is to make sure we could have the following pattern: | ||
bootstrap.js (starting point, simply one-liner) | |||
<pre> | <pre> | ||
// | // (we need to expose the system instance because test atoms need to call some functions directly) | ||
window.system = new System(); | |||
</pre> | </pre> | ||
system.js (the "root" of the all modules, starts the "world") | |||
<pre> | |||
var System = function System() { | |||
this.appWindowFactory = new AppWindowFactory(this); | |||
this.appWindowManager = new AppWindowManager(this); | |||
this.screenManager = new ScreenManager(this); | |||
}; | |||
.. prototype methods follows .. | |||
</pre> | |||
'''Caveat''': Please take care of instantiation timing and dependency. Please ensure the rewrite does not break anything (run tests!). If you think the parent instance need explicit control over initialization, you may create <code>init()</code> and more some code there. | |||
With this pattern we are able to do unit test anywhere, | With this pattern we are able to do unit test anywhere, | ||
and | and there's no architecture design involved in this stage. | ||
Even a new employee could take one of the modules to rewrite it correctly. | Even a new employee could take one of the modules to rewrite it correctly. | ||