Skip to content

Commit

Permalink
Merge f970cce into 50b533b
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekosDordas committed Jul 5, 2019
2 parents 50b533b + f970cce commit aaee549
Show file tree
Hide file tree
Showing 8 changed files with 10,880 additions and 9 deletions.
19 changes: 16 additions & 3 deletions dist/handlebars-layouts.js
Expand Up @@ -55,6 +55,12 @@ function applyAction(val, action) {
return fn();
}

case 'data': {
if (context[action.as] === undefined) context[action.as] = [];
context[action.as].push(fn());
context.$$hasData = true;
}

default: {
return val;
}
Expand Down Expand Up @@ -165,14 +171,19 @@ function layouts(handlebars) {

var fn = options.fn || noop,
data = handlebars.createFrame(options.data),
context = this || {};
context = this || {},
result = noop;

applyStack(context);

return getActionsByName(context, name).reduce(
result = getActionsByName(context, name).reduce(
applyAction.bind(context),
fn(context, { data: data })
);

if (context.$$hasData) result = fn(context, { data: data });

return result;
},

/**
Expand All @@ -191,6 +202,7 @@ function layouts(handlebars) {
data = handlebars.createFrame(options.data),
hash = options.hash || {},
mode = hash.mode || 'replace',
as = hash.mode === 'data' ? hash.as || 'block-items' : noop,
context = this || {};

applyStack(context);
Expand All @@ -204,6 +216,7 @@ function layouts(handlebars) {
getActionsByName(context, name).push({
options: { data: data },
mode: mode.toLowerCase(),
as: as,
fn: fn
});
}
Expand Down Expand Up @@ -231,4 +244,4 @@ layouts.register = function (handlebars) {
module.exports = layouts;

},{}]},{},[1])(1)
});
});
17 changes: 15 additions & 2 deletions index.js
Expand Up @@ -54,6 +54,12 @@ function applyAction(val, action) {
return fn();
}

case 'data': {
if (context[action.as] === undefined) context[action.as] = [];
context[action.as].push(fn());
context.$$hasData = true;
}

default: {
return val;
}
Expand Down Expand Up @@ -164,14 +170,19 @@ function layouts(handlebars) {

var fn = options.fn || noop,
data = handlebars.createFrame(options.data),
context = this || {};
context = this || {},
result = noop;

applyStack(context);

return getActionsByName(context, name).reduce(
result = getActionsByName(context, name).reduce(
applyAction.bind(context),
fn(context, { data: data })
);

if (context.$$hasData) result = fn(context, { data: data });

return result;
},

/**
Expand All @@ -190,6 +201,7 @@ function layouts(handlebars) {
data = handlebars.createFrame(options.data),
hash = options.hash || {},
mode = hash.mode || 'replace',
as = hash.mode === 'data' ? hash.as || 'block-items' : noop,
context = this || {};

applyStack(context);
Expand All @@ -203,6 +215,7 @@ function layouts(handlebars) {
getActionsByName(context, name).push({
options: { data: data },
mode: mode.toLowerCase(),
as: as,
fn: fn
});
}
Expand Down

0 comments on commit aaee549

Please sign in to comment.