Since I wrote this I have explored ac.composite.execute more in depth and found several goodies which come handy regarding this and my other
post about communicating with children.
Anyway, back to this, it would seem that the guy who wrote ac.composite.done had not talked with whomever did ac.done or, if the same person, suffered from amnesia in between the two. It would be easier if the two method were more alike. If it is
ac.done(data, opts);
it would make sense that it should be
ac.composite.done(data, opts);
and not
ac.composite.done({template: data});
However, this is what I would like to suggest:
ac.done = (function (original) { return function (data, opts) { var instance = ac.command.instance, config = instance.config, action = instance.action, params = ac.params, me = this; if (config.hasOwnProperty('child')) { config.children = {child:config.child}; delete config.child; } if (!config.children) { return original.apply(this, arguments); } Y.each(config.children, function (opt) { opt.action = opts.action || action || opt.action; opt.params = Y.merge(opt.params, params, opts.params); }); Y.mix(config.children, opts.children); ac.composite.execute(config, function (childData, meta) { original.call(me, Y.merge(data, childData), meta); }); };})(ac.done);
I am inserting the code above right after each action method that receives an action context in order to redefine it on the spot. I don't really know where things are in Mojito (at least so far) so I can't patch it where I should so I improvised the patch above.
So, what this does is to redefine ac.done so that it does what ac.composite.done does and, to some extent, what ac.composite.execute does.
Basically, if it finds no child or children configuration in application.json it calls ac.done() as before. If there is a child declaration there, it changes it to a children declaration and gives it a 'child' slot name.
Then, for each of the children, as read from application.json, it allows for several overrides.
A params option allows you to merge extra parameters into all children config. This may be overridden by specific params settings on any of the children.
Also, the action option is taken from one explicitly set for that child, from a generic action option or from the action option of the parent mojit.
Finally, a general merge allows for piling up all other settings which may override those in application.json.
When that is done, it calls ac.composite.execute with that new configuration. On return, it merges the data from the parent with that returned from the children and its metadata and calls the original ac.done.
In this way, ac.done() combined with the settings coming from application.json and any possible overrides works in the same way both for regular mojits and composite ones. It allows for several ways to provide overrides, generic ones and specific ones and spares going through ac.composite.execute.
(continues ....)