Skip to content

Commit

Permalink
Merge 219f1d7 into 7ca3278
Browse files Browse the repository at this point in the history
  • Loading branch information
belozer committed Jun 19, 2018
2 parents 7ca3278 + 219f1d7 commit 0fa1f91
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
11 changes: 10 additions & 1 deletion common.blocks/i-bem-dom/i-bem-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function initEntity(entityName, domElem, params, ignoreLazyInit, callback) {

entityCls._processInit();

if(!entityCls.lazyInit || ignoreLazyInit || params.lazyInit === false) {
if(ignoreLazyInit || params.lazyInit === false || !entityCls.lazyInit && !params.lazyInit) {
ignoreLazyInit && domElem.addClass(BEM_CLASS_NAME); // add css class for preventing memory leaks in further destructing

entity = new entityCls(uniqIdToDomElems[uniqId], params, !!ignoreLazyInit);
Expand Down Expand Up @@ -768,6 +768,15 @@ var BemDomEntity = inherit(/** @lends BemDomEntity.prototype */{
throw Error('bemDom entities can not be created otherwise than from DOM');
},

/** @override */
declMod : function(mod, props, staticProps) {
if(staticProps && staticProps.lazyInit !== undef) {
throw Error('declMod with lazyInit prop not allowed. Your need use \'lazyInit\' in data-bem params');
}

return this.__base.apply(this, arguments);
},

/** @override */
_processInit : function(heedInit) {
/* jshint eqeqeq: false */
Expand Down
31 changes: 31 additions & 0 deletions common.blocks/i-bem-dom/i-bem-dom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ describe('i-bem-dom', function() {
block2.should.be.instanceOf(Block1);
elem2.should.be.instanceOf(Elem1);
});

it('should throw error if declMod contains lazyInit static property', function() {
var Block = bemDom.declBlock('block');

function mod() {
Block.declMod({ modName : 'mod' }, null, { lazyInit : true });
}

mod.should.throw(Error, 'declMod with lazyInit prop not allowed. Your need use \'lazyInit\' in data-bem params');
});
});

describe('getMod', function() {
Expand Down Expand Up @@ -1686,6 +1696,27 @@ describe('i-bem-dom', function() {
spy.should.have.been.called;
});

it('should be possible to force lazy initialization', function() {
spy = sinon.spy();

bemDom.declBlock('block', {
onSetMod : {
'js' : {
'inited' : spy
}
}
}, {
lazyInit : false
});

rootNode = initDom({
block : 'block',
js : { lazyInit : true }
});

spy.should.have.not.been.called;
});

describe('on DOM events', function() {
beforeEach(function() {
spy = sinon.spy();
Expand Down

0 comments on commit 0fa1f91

Please sign in to comment.