Composite.common Class
Access point: ac.composite.* Provides methods for working with many Mojits.
Methods
addChild
-
childName -
child
This method allow you to add more childs into the queue of children
manually. By default, the config.children structure will be processed
when calling ac.composite.done, but you can add more childs programatically
before or after calling ac.composite.done if you need to.
This is useful when you want to have more control over the children collection.
ac.composite.addChild('slot-1', {
type: "foo",
action: "index"
})
Parameters:
-
childNameStringThe mojit instance name that will be used in a template in a form of {{{
}}}. -
childObjectThe configuration object for the child.
Returns:
done
-
templateData -
parentMeta
Automatically dispatches all the children of this mojit and collects their executed values into the view template, keyed by the child's name within the mojit's configuration. For example, given the mojit spec:
"specs": {
"parent": {
"type": "MyCompositeMojit",
"config": {
"children": {
"foo": {
"type": "FooMojit"
},
"bar": {
"type": "BarMojit"
}
}
}
}
}
And given the view template:
<div id="{{mojit_view_id}}">
<h1>{{title}}</h1>
<div class="fooslot">
{{{foo}}}
</div>
<div class="barslot">
{{{bar}}}
</div>
</div>
And the controller:
Y.mojito.controller = {
index: function(ac) {
ac.composite.done({
title: 'Hello there'
});
}
};
This will execute the child intances of the "FooMojit" and "BarMojit", returning their rendered values into the parent's view template, thus rendering the full parent view including the children. The API of this method is equivalent to ac.done().
Parameters:
-
templateDataObjectThe data you want return by the request.
-
parentMetaObjectAny meta-data required to service the request.
execute
-
cfg -
cb
This method requires an explicit config object and returns a RMP compliant object via a callback.
cfg = {
children: {
slot-1: {
type: "default",
action: "index"
},
slot-2: {
type: "default",
action: "index",
params: {
route: {},
url: {},
body: {},
file: {}
}
}
},
assets: {}
}
The "callback" is an object containg the child slots with its rendered data.
callback({
slot-1: ,
slot-2:
},
{
http: {}
assets: {}
})
Parameters:
-
cfgObjectThe configuration object to be used.
-
cbFunctionThe callback that will be called.
