Skip to content

Commit

Permalink
Add support for modVal : '*' in declMod (closes #1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfilatov committed Jun 20, 2016
1 parent 44c1c9a commit 36b2061
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions common.blocks/i-bem/i-bem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,32 @@ describe('i-bem', function() {
baseMethodSpy.should.have.been.calledOnce;
modsMethodSpy.should.have.been.calledOnce;
});

it('should apply method if block has any mod', function() {
var baseMethodSpy = sinon.spy(),
modsMethodSpy = sinon.spy(),
Block = bem
.declBlock('block', { method : baseMethodSpy })
.declMod({ modName : 'mod1', modVal : '*' }, { method : modsMethodSpy }),
instance = new Block({ mod1 : 'val1' });

instance.method();

baseMethodSpy.should.not.have.been.called;
modsMethodSpy.should.have.been.calledOnce;

instance.setMod('mod1', 'val2');
instance.method();

baseMethodSpy.should.not.have.been.called;
modsMethodSpy.should.have.been.calledTwice;

instance.delMod('mod1');
instance.method();

baseMethodSpy.should.have.been.calledOnce;
modsMethodSpy.should.have.been.calledTwice;
});
});

describe('create', function() {
Expand Down
7 changes: 6 additions & 1 deletion common.blocks/i-bem/i-bem.vanilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,13 @@ function buildCheckMod(modName, modVal) {
}

function checkMod(block, modName, modVal) {
var prevModVal = block._processingMods[modName];

// check if a block has either current or previous modifier value equal to passed modVal
return block.hasMod(modName, modVal) || block._processingMods[modName] === modVal;
return modVal === '*'?
/* jshint eqnull: true */
block.hasMod(modName) || prevModVal != null :
block.hasMod(modName, modVal) || prevModVal === modVal;
}

function convertModHandlersToMethods(props) {
Expand Down

0 comments on commit 36b2061

Please sign in to comment.