Skip to content

Commit

Permalink
BEMXJST: allow apply() inside match() (fix for #309)
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Jan 10, 2017
1 parent c54f2f7 commit 88d7949
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/bemxjst/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,16 @@ BEMXJST.prototype.applyNext = function applyNext() {
};

BEMXJST.prototype.applyMode = function applyMode(mode, changes) {
var match = this.match.entity.rest[mode];
var key;
var match = this.match;

if (!match) {
var key = this.classBuilder.build(this.context.block, this.context.elem);
match = this.entities[key].rest[mode];
} else {
match = this.match.entity.rest[mode];
}

if (!match) {
if (mode === 'mods')
return this.context.mods;
Expand Down
24 changes: 24 additions & 0 deletions test/modes-match-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,28 @@ describe('Modes match', function() {
block: 'bla'
}, '<span class="bla"></span>');
});

it('should work with apply() inside match()',
function() {
test(function() {
block('b')(
mode('test')(function() { return true; }),

match(function() { return apply('test'); })
.content()(function() { return 'OK'; })
);
}, { block: 'b' }, '<div class="b">OK</div>');
});

it('should work with apply() with changes inside match()',
function() {
test(function() {
block('b')(
mode('test')(function() { return this.changes; }),

match(function() { return apply('test', { changes: true }); })
.content()(function() { return 'OK'; })
);
}, { block: 'b' }, '<div class="b">OK</div>');
});
});

0 comments on commit 88d7949

Please sign in to comment.