Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions mithril.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,18 @@ var m = (function app(window, undefined) {
return data;
}

function buildObject(data, cached, editable, parentElement, index, shouldReattach, namespace, configs) {
function makeRedrawSelf(controller,view,parentElement, parentTag, parentCache, parentIndex, newData, cached, shouldReattach, index, editable, namespace, configs) {
return function() {
m.redraw.strategy('none');
var newData = view(controller);
build(parentElement, parentTag, parentCache, parentIndex, newData, cached, shouldReattach, index, editable, namespace, configs);
}
}

function buildObject(parentElement, parentTag, parentCache, parentIndex, data, cached, shouldReattach, index, editable, namespace, configs) {
var views = [], controllers = [];
data = markViews(data, cached, views, controllers);
if (!data.tag && controllers.length) throw new Error("Component template must return a virtual element, not an array, string, etc.");
if (!data.tag && controllers.length) throw new Error("Component template must return a virtual element, not an array, string, etc.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace

data.attrs = data.attrs || {};
cached.attrs = cached.attrs || {};
var dataAttrKeys = Object.keys(data.attrs);
Expand All @@ -487,6 +495,15 @@ var m = (function app(window, undefined) {
//schedule configs to be called. They are called after `build`
//finishes running
scheduleConfigsToBeCalled(configs, data, node, isNew, cached);

// Single component redraw fix
for (var i = 0; i < controllers.length; i++) {
var controller = controllers[i];
if (isFunction(controller.redrawSelf)) {
controller.redrawSelf = makeRedrawSelf(controller,views[i],parentElement, parentTag, parentCache, parentIndex, data, cached, shouldReattach, index, editable, namespace, configs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need spaces after commas

}
}

return cached
}

Expand Down Expand Up @@ -544,7 +561,7 @@ var m = (function app(window, undefined) {
if (data.subtree === "retain") return cached;
cached = makeCache(data, cached, index, parentIndex, parentCache);
return isArray(data) ? buildArray(data, cached, parentElement, index, parentTag, shouldReattach, editable, namespace, configs) :
data != null && isObject(data) ? buildObject(data, cached, editable, parentElement, index, shouldReattach, namespace, configs) :
data != null && isObject(data) ? buildObject(parentElement, parentTag, parentCache, parentIndex, data, cached, shouldReattach, index, editable, namespace, configs) :
!isFunction(data) ? handleText(cached, data, index, parentElement, shouldReattach, editable, parentTag) :
cached;
}
Expand Down