Skip to content

Commit

Permalink
Fix map of actions attached to app's root element.
Browse files Browse the repository at this point in the history
`Html`'s map instance is a foreign function for performance optimizations. This
foreign function was not properly mapping actions on the root element of the
virtual DOM tree.
  • Loading branch information
alexmingoia committed Apr 27, 2016
1 parent 51cc5cb commit 4e68bc8
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/Pux.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,37 @@ exports.fromReact = function (comp) {
};

exports.render = function (input, parentAction, html) {
var props = html.props
var newProps = {};

for (var key in props) {
if (key !== 'puxParentAction' && typeof props[key] === 'function') {
newProps[key] = props[key](input, parentAction);
}
}

var newChildren = React.Children.map(html.props.children, function (child) {
var childAction = child.props && child.props.puxParentAction;
function composeAction(parentAction, html) {
var childAction = html.props && html.props.puxParentAction;
var action = parentAction;
if (childAction) {
action = function (a) {
return parentAction(childAction(a));
};
}
if (typeof child === 'string') {
return child;
} else {
return exports.render(input, action, child);
return action;
}

function render(input, parentAction, html) {
var props = html.props
var newProps = {};

for (var key in props) {
if (key !== 'puxParentAction' && typeof props[key] === 'function') {
newProps[key] = props[key](input, parentAction);
}
}
});

return React.cloneElement(html, newProps, newChildren);
var newChildren = React.Children.map(html.props.children, function (child) {
if (typeof child === 'string') {
return child;
} else {
return render(input, composeAction(parentAction, child), child);
}
});

return React.cloneElement(html, newProps, newChildren);
}

return render(input, composeAction(parentAction, html), html);
};

0 comments on commit 4e68bc8

Please sign in to comment.