Gaia/System/Refactoring Plan: Difference between revisions

no edit summary
No edit summary
Line 5: Line 5:
== Target ==
== Target ==
The main purposes/targets are:
The main purposes/targets are:
# Mminimize the memory usage of the system app
# 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>
// in bootstrap.js (main function, one line only expected.)
new System();


// in system.js
// (we need to expose the system instance because test atoms need to call some functions directly)
this.appWindowFactory = new AppWindowFactory(this);
window.system = new System();
this.appWindowManager = new AppWindowManager(this);
 
this.screenManager = new ScreenManager(this);
</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 there’s no architecture design involved in this stage.
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.


Confirmed users
478

edits