Skip to content

Commit

Permalink
slots support for functional components
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Feb 14, 2017
1 parent 25bd312 commit 07f9317
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
32 changes: 28 additions & 4 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@
return compiled;
};

/**
* Extracts the Slots From Component Children
* @param {Array} children
* @return {Object} extracted slots
*/
var getSlots = function (children) {
var slots = {};

// No Children Means No Slots
if (!children) {
return slots;
}

slots.default = [];

for (var i = 0; i < children.length; i++) {
var child = children[i];
slots.default.push(child);
}

return slots;
};

/**
* Creates a Virtual DOM Node
* @param {String} type
Expand Down Expand Up @@ -133,9 +156,9 @@
* @param {Object} component
* @return {Object} Virtual DOM Node
*/
var createComponent = function (type, props, children, meta, component) {
var createComponent = function (type, props, meta, children, component) {
if (component.opts.functional) {
return createFunctionalComponent(type, props, children, meta, component);
return createFunctionalComponent(type, props, meta, children, component);
}
};

Expand All @@ -148,7 +171,7 @@
* @param {Object} functionalComponent
* @return {Object} Virtual DOM Node
*/
var createFunctionalComponent = function (type, props, children, meta, functionalComponent) {
var createFunctionalComponent = function (type, props, meta, children, functionalComponent) {
var data = functionalComponent.opts.data || {};
// Merge data with provided props
if (functionalComponent.opts.props) {
Expand All @@ -158,7 +181,8 @@
}
}
return functionalComponent.opts.render(h, {
data: data
data: data,
slots: getSlots(children)
});
};

Expand Down
Loading

0 comments on commit 07f9317

Please sign in to comment.