[ALOY-506] Alloy: Adding hooks for pre UI code

GitHub Issuen/a
TypeNew Feature
Affected Version/sAlloy 0.3.1
Fix Version/sn/a
ComponentsModels, Runtime
Labelsalloy, compiler
ReporterMads Moller


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.


  1. Peter Eddy Pritchard 2014-10-05 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)

JSON Source