Permalink
Browse files

Widget's constructor now does a config = config || {} before chaining

to Base's constructor, so that HTML_PARSER works when constructing
a widget without providing a configuration object.

This could happen when srcNode is defined statically. Rare, but probable
use case for JS Widgets which are tightly bound to server side HTML impls.

Fixes #2531501

Ran all unit.xml units tests through yeti, since this is fairly low level.
  • Loading branch information...
1 parent 8f6d1ab commit 6b7baaa39136d411805ffeac06cc81f3af043085 @sdesai committed Feb 29, 2012
@@ -96,7 +96,10 @@ function Widget(config) {
widget._strs = {};
widget._cssPrefix = constructor.CSS_PREFIX || _getClassName(constructor.NAME.toLowerCase());
- Widget.superclass.constructor.apply(widget, arguments);
+ // We need a config for HTML_PARSER to work.
+ config = config || {};
+
+ Widget.superclass.constructor.call(widget, config);
render = widget.get(RENDER);

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -95,7 +95,10 @@ function Widget(config) {
widget._strs = {};
widget._cssPrefix = constructor.CSS_PREFIX || _getClassName(constructor.NAME.toLowerCase());
- Widget.superclass.constructor.apply(widget, arguments);
+ // We need a config for HTML_PARSER to work.
+ config = config || {};
+
+ Widget.superclass.constructor.call(widget, config);
render = widget.get(RENDER);
View
@@ -15,6 +15,13 @@ Widget Change History
listener and using Widget.getByNode to ship out handling to the specific widget
instance.
+ * Widget will now default to an empty object config, if one isn't passed in,
+ so that HTML_PARSER can work with a static ATTRS srcNode definition.
+
+ It's not possible to address this just at the HTML_PARSER level, since the config
+ object gets used by reference, so we need to make sure everything is updating the
+ config object which is passed to Base's initialization chain.
+
3.4.1
-----
View
@@ -94,7 +94,10 @@ function Widget(config) {
widget._strs = {};
widget._cssPrefix = constructor.CSS_PREFIX || _getClassName(constructor.NAME.toLowerCase());
- Widget.superclass.constructor.apply(widget, arguments);
+ // We need a config for HTML_PARSER to work.
+ config = config || {};
+
+ Widget.superclass.constructor.call(widget, config);
render = widget.get(RENDER);
@@ -1743,6 +1743,46 @@
Y.Assert.areSame("Item2", w.get("listNodes").item(1).get("text"), "listNode 1 not picked up from markup");
w.destroy();
+ },
+
+ "testHTMLParserWithEmptyConfig" : function() {
+
+ // See http://yuilibrary.com/projects/yui3/ticket/2531501
+
+ // User wanted to have a Widget with a statically defined srcNode (a rare use case),
+ // which meant there was no need to pass a config object to the widget constructor,
+ // bringing out a logic issue, when using html parser and no config
+
+ var markup = Y.Node.create('<div id="staticSrcNode"><h1>My Label</h1><ul><li>Item1</li><li>Item2</li></ul></div>');
+ Y.Node.one("body").append(markup);
+
+ function StaticSrcNodeWidget() {
+ StaticSrcNodeWidget.superclass.constructor.apply(this, arguments);
+ }
+
+ Y.extend(StaticSrcNodeWidget, MyCustomWidget, null, {
+ ATTRS : {
+ srcNode : {
+ value: "#staticSrcNode"
+ }
+ },
+ NAME : "staticSrcNodeWidget"
+ })
+
+ var w = new StaticSrcNodeWidget();
+
+ Y.Assert.areEqual("My Label", w.get("label"), "label not picked up from markup");
+ Y.Assert.areEqual("h1", w.get("titleNode").get("tagName").toLowerCase(), "titleNode not picked up from markup");
+
+ Y.Assert.areEqual(2, w.get("listNodes").size(), "listNodes count does not match markup");
+
+ Y.Assert.areSame("li", w.get("listNodes").item(0).get("tagName").toLowerCase(), "listNode 0 not picked up from markup");
+ Y.Assert.areSame("li", w.get("listNodes").item(1).get("tagName").toLowerCase(), "listNode 1 not picked up from markup");
+
+ Y.Assert.areSame("Item1", w.get("listNodes").item(0).get("text"), "listNode 0 not picked up from markup");
+ Y.Assert.areSame("Item2", w.get("listNodes").item(1).get("text"), "listNode 1 not picked up from markup");
+
+ w.destroy();
}
}));

0 comments on commit 6b7baaa

Please sign in to comment.