Skip to content

Commit

Permalink
Added use component default value if parent context key is not set. (#11
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fabianmarz authored Jun 5, 2019
1 parent 42be321 commit 1993ef5
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/tags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,23 @@ module.exports = function(fractal){

if (token.withStack !== undefined) {
passedArguments = Twig.expression.parse.apply(this, [token.withStack, context]);

_.forEach(passedArguments, function (value, name) {
// It makes no sense to pass variables that are not
// supported by the component.
if (innerContext[name] === undefined) {
return;
}
if (name.indexOf('attributes') > -1) {
innerContext[name].merge(value);
}
else {
innerContext[name] = value;
}
// Variables not defined by the component context are
// intentionally ignored.
_.forEach(innerContext, function (value, name) {
// Override default value only if an argument value is passed.
// Ignore undefined variables, which may appear when rendering
// a component with dummy/faker data but without values for its
// child components, so that each component only generates its
// own dummy data.
if (!passedArguments.hasOwnProperty(name) || typeof passedArguments[name] === 'undefined') {
return;
}
if (name.indexOf('attributes') > -1) {
value.merge(passedArguments[name]);
}
else {
innerContext[name] = passedArguments[name];
}
});
}

Expand Down

0 comments on commit 1993ef5

Please sign in to comment.