Skip to content

Commit

Permalink
Merge pull request #61 from asudoh/WidgetList
Browse files Browse the repository at this point in the history
Support for objects in data-mvc-child-type and data-mvc-child-mixins.
  • Loading branch information
edchat committed Oct 22, 2012
2 parents cab5b6e + 7fbf109 commit 027936c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
12 changes: 10 additions & 2 deletions WidgetList.js
Expand Up @@ -10,7 +10,8 @@ define([
var childTypeAttr = "data-mvc-child-type",
childMixinsAttr = "data-mvc-child-mixins",
childParamsAttr = "data-mvc-child-props",
childBindingsAttr = "data-mvc-child-bindings";
childBindingsAttr = "data-mvc-child-bindings",
undef;

function evalParams(params){
return eval("({" + params + "})");
Expand Down Expand Up @@ -209,7 +210,14 @@ define([
if(this.childClz){
createAndWatch(this.childClz);
}else if(this.childType){
require([this.childType].concat(this.childMixins && this.childMixins.split(",") || []), createAndWatch);
var types = [this.childType].concat(this.childMixins && this.childMixins.split(",") || []),
mids = array.filter(array.map(types, function(type){ return lang.getObject(type) ? undef : type; }), function(mid){ return mid !== undef; }),
_self = this;
require(mids, function(){
if(!self._beingDestroyed){
createAndWatch.apply(this, array.map(types, function(type){ return lang.getObject(type) || require(type); }));
}
});
}else{
createAndWatch(Templated);
}
Expand Down
31 changes: 30 additions & 1 deletion tests/WidgetList.js
@@ -1,12 +1,20 @@
define([
"doh",
"dojo/_base/array",
"dojo/_base/config",
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dijit/_Container",
"dijit/form/TextBox",
"dojox/mvc/at",
"dojox/mvc/getStateful",
"dojox/mvc/WidgetList",
"dojo/text!dojox/mvc/tests/test_WidgetList_WidgetListInTemplate.html",
"dojo/text!dojox/mvc/tests/test_WidgetList_childTemplate.html",
"dojo/text!dojox/mvc/tests/test_WidgetList_childBindings.json"
], function(doh, config, at, getStateful, WidgetList, childTemplate, childBindings){
], function(doh, array, config, declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container, _TextBox, at, getStateful, WidgetList, template, childTemplate, childBindings){
var a = getStateful([
{
Serial: "A111",
Expand Down Expand Up @@ -165,6 +173,27 @@ define([
wl0.set("children", "foo");
children = wl0.getChildren();
doh.is(0, children.length, "The widget list should be empty");
},
function objectInChildType(){
var data = [{idx: 0}, {idx: 1}, {idx: 2}, {idx: 3}];

declare("My.Widget", _WidgetBase, {
isMyWidget: true
});
declare("My.Mixin", null, {
isMyMixin: true
});

var w = new (declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {templateString: template}))({childData: data});
w.startup();

var simpleChildren = w.simpleWidgetList.getChildren(),
simpleChildrenWithRegularDijit = w.simpleWidgetListWithRegularDijit.getChildren(),
simpleChildrenWithRegularDijitInMixin = w.simpleWidgetListWithRegularDijitInMixin.getChildren()

doh.t(array.every(simpleChildren, function(child){ return child.isMyWidget && child.isMyMixin && !child.addChild && !child._setValueAttr; }), "simpleChildren should be created by My.Widget and My.Mixin");
doh.t(array.every(simpleChildrenWithRegularDijit, function(child){ return !child.isMyWidget && child.isMyMixin && !child.addChild && child._setValueAttr; }), "simpleChildrenWithRegularDijit should be created by dijit/form/TextBox and My.Mixin");
doh.t(array.every(simpleChildrenWithRegularDijitInMixin, function(child){ return child.isMyWidget && child.isMyMixin && child.addChild && !child._setValueAttr; }), "simpleChildrenWithRegularDijitInMixin should be created by My.Widget, My.Mixin and dijit/_Container");
}
]);
});
20 changes: 20 additions & 0 deletions tests/test_WidgetList_WidgetListInTemplate.html
@@ -0,0 +1,20 @@
<div>
<div data-dojo-attach-point="simpleWidgetList"
data-dojo-type="dojox/mvc/WidgetList"
data-mvc-child-type="My.Widget"
data-mvc-child-mixins="My.Mixin"
data-dojo-props="children: this.childData">
</div>
<div data-dojo-attach-point="simpleWidgetListWithRegularDijit"
data-dojo-type="dojox/mvc/WidgetList"
data-mvc-child-type="dijit/form/TextBox"
data-mvc-child-mixins="My.Mixin"
data-dojo-props="children: this.childData">
</div>
<div data-dojo-attach-point="simpleWidgetListWithRegularDijitInMixin"
data-dojo-type="dojox/mvc/WidgetList"
data-mvc-child-type="My.Widget"
data-mvc-child-mixins="My.Mixin,dijit/_Container"
data-dojo-props="children: this.childData">
</div>
</div>

0 comments on commit 027936c

Please sign in to comment.