Skip to content

Commit

Permalink
fix: decouple mu-jquery-loom
Browse files Browse the repository at this point in the history
Previously we asumed you'd be using `mu-jquery-loom` for hooking your widgets and elements up but that's not always true so we changed `walk` to take a method that returns the `$element` we're attaching to the dom, nothing more.

BREAKING CHANGE: `walk` signature change.
  • Loading branch information
mikaelkaron committed Apr 25, 2017
1 parent 9f59622 commit 271faa6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
9 changes: 3 additions & 6 deletions examples/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
}));
}
})(["mu-jquery-widget/widget", "../walk"], function (widget, walk) {
function conf(json) {
return {
"element": "<" + json["@component"] + ">",
"widget": "mu-jquery-widget-cyoa/widget"
};
function create(json) {
return this.$("<" + json["@component"] + ">", { "mu-widget": "mu-jquery-widget-cyoa/widget" });
}

return widget.extend({
Expand All @@ -27,7 +24,7 @@
throw new Error("data.json [" + textStatus + "] " + errorThrown);
})
.then(function (json) {
return me.$element.append(walk.call(me, me.json = json, conf)).weave();
return me.$element.append(walk.call(me, me.json = json, create)).weave();
});
}
})
Expand Down
12 changes: 6 additions & 6 deletions walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
root["mu-jquery-widget-cyoa/walk"] = factory.apply(root, modules);
}
})([], function () {
return function walk(json, conf) {
return function walk(json, create) {
var me = this;
var $ = me.$;
var parent = function () {
return json;
};
var $children = $.map(json["@children"] || false, function (child) {
child.parent = parent;
return walk.call(me, child, conf);
return walk.call(me, child, create);
});
var cfg = conf.call(me, json);
var $element = create.call(me, json);

return cfg
? $(cfg.element, { "mu-widget": cfg.widget })
.data("muJqueryWidgetCyoa", json)
return $element
? $element
.data("mu-jquery-widget-cyoa", json)
.append($children)
: $children;
}
Expand Down
2 changes: 1 addition & 1 deletion widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
})(["mu-jquery-widget/widget"], function (widget) {
return widget.extend(function ($element, ns) {
var me = this;
var json = me.json = $element.data("muJqueryWidgetCyoa");
var json = me.json = $element.data("mu-jquery-widget-cyoa");

json.widget = function () {
return me;
Expand Down

0 comments on commit 271faa6

Please sign in to comment.