[ALOY-506] Alloy: Adding hooks for pre UI code
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Medium |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Alloy 0.3.1 |
Fix Version/s | n/a |
Components | Models, Runtime |
Labels | alloy, compiler |
Reporter | Mads Moller |
Assignee | Unknown |
Created | 2013-01-21T20:46:58.000+0000 |
Updated | 2018-03-07T22:26:11.000+0000 |
Description
Hi Tony,
We need to figure out a way to add hooks to execute code before markup are rendered.
You wrote:
There _needs_ to be a way to execute code before the markup. Unfortunately, this is likely going to require some restructuring in order to maintain valid JS in the developer-written controller code while maintaing their simplicity. Right now controllers are a flat chunk of Javascript. To effectively allow for lifecycle events like "preUI" that need to be executed out of order, a more strict commonjs structure might need to be created for the controllers. Something like this:
exports.preUI = function($) {
// code executed before UI is created, has access to $
// but it has not been populated by UI creation yet.
// $ would be an empty object at this point. you can
// initialize models/collections for binding,
// dynamically updated styles before they are applied,
// handle Mads' use case, etc...
}
exports.ready = function($) {
// this would be the normal controller code, it has
// access to the populated $ variable.
}
exports.someProperty = 'skjhdsdjhfjksd';
exports.someCustomFunction = function() {
// export functions & vars just like you did before
}
I believe this only should be optional. No need for beginners to know this kind of functionality.
is this a duplicate of ALOY-744? the same proposed solution works for ALOY-1037 and other issues as well (see comments in related issues)