Fix the need for the onReady event
jsguy opened this issue · 2 comments
jsguy commented
Fix the need for using the onReady event - probably use same pattern as mithril does, within the base framework, and make the "store" component manage the subscription.
StephanHoyer commented
I now use Promise.all
for this
function controller(params, done) {
var scope = {
// view context data
};
var firstAjaxDone = store.load('thing1', 123).then(function(thing1) {
scope.thing1 = thing1;
});
var secondAjaxDone = store.load('thing2', 321).then(function(thing2) {
scope.thing2 = thing2;
});
scope.onunload = function onunload() {
//unload all the things
};
done && Promise.all([firstAjaxDone, secondAjaxDone]).then(function() {
done(null, scope);
});
return scope;
}
Also I use a done
-Callback. This is used only on server side.
jsguy commented
Ah ok neat. I just committed a change to remove this from the controller entirely - it's a little more generic, and allows the library that is loading things to handle the blocking till it is done.
Looks like we ended up working on the same thing :)
I always assign a ticket to myself, if I'm working on it.