Skip to content

Commit

Permalink
BEMXJST: applyCtx should reset position
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Apr 28, 2017
1 parent 693c49c commit 578c89a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/bemxjst/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ BEMXJST.prototype.compile = function(code) {
var self = this;

function applyCtx() {
return self.run(self.context.ctx);
}

function _applyCtx() {
return self._run(self.context.ctx);
}

Expand All @@ -59,7 +63,7 @@ BEMXJST.prototype.compile = function(code) {
return self.local({ ctx: ctx }, applyCtx);

return self.local(changes, function() {
return self.local({ ctx: ctx }, applyCtx);
return self.local({ ctx: ctx }, _applyCtx);
});
}

Expand Down
15 changes: 15 additions & 0 deletions test/bemcontext-position-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,19 @@ describe('BEMContext this.position', function() {
'<div class="b b_last_yes p_3"></div>' +
'</div>');
});

it('should properly set position with applyCtx()', function() {
test(function() {
block('a')(
def()(function() {
applyCtx({ block: 'session' });
applyCtx({ block: 'session' });
return applyNext();
}),
cls()(function() { return this.position; })
);
},
[ { block: 'a' }, { block: 'a' }, { block: 'a' } ],
'<div class="a 1"></div><div class="a 2"></div><div class="a 3"></div>');
});
});

0 comments on commit 578c89a

Please sign in to comment.