Skip to content

Commit

Permalink
runtime: lazily set mods
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Apr 27, 2015
1 parent 3f9e352 commit 8b8ab29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/bemhtml/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ BEMHTML.prototype.runOne = function runOne(json) {
context.ctx = json;
if (json.block) {
context.block = json.block;
context.mods = json.mods;

// TODO(indutny): this might be a performance hit, consider it
context.mods = json.mods || {};
} else if (!json.elem) {
context.block = '';
} else if (oldCurrBlock) {
Expand Down
8 changes: 8 additions & 0 deletions test/runtime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ describe('BEMHTML compiler/Runtime', function() {
}, { tag: false, content: 'ok' }, 'ok');
});

it('should lazily define mods', function() {
test(function() {
block('b1').content()(function() {
return this.mods.a || 'yes';
});
}, { block: 'b1' }, '<div class="b1">yes</div>');
});

describe('mix', function() {
it('should avoid loops', function() {
test(function() {
Expand Down

0 comments on commit 8b8ab29

Please sign in to comment.