Skip to content

Commit

Permalink
optimize prop merger for functional components, add all props by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Jun 3, 2017
1 parent b133e86 commit 2fae857
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
17 changes: 12 additions & 5 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,22 @@
* @return {Object} Virtual DOM Node
*/
var createFunctionalComponent = function (props, children, functionalComponent) {
var data = functionalComponent.options.data || {};
var options = functionalComponent.options;
var attrs = props.attrs;
var data = options.data;

// Merge data with provided props
if (functionalComponent.options.props !== undefined) {
var propNames = functionalComponent.options.props;
if (data === undefined) {
data = {};
}

// Merge data with provided props
var propNames = options.props;
if (propNames === undefined) {
data = attrs;
} else {
for (var i = 0; i < propNames.length; i++) {
var prop = propNames[i];
data[prop] = props.attrs[prop];
data[prop] = attrs[prop];
}
}

Expand Down
Loading

0 comments on commit 2fae857

Please sign in to comment.