@@ -153,7 +153,7 @@ function initEntity(entityName, domElem, params, ignoreLazyInit, callback) {
153153
154154 entityCls . _processInit ( ) ;
155155
156- if ( ignoreLazyInit || params . lazyInit === false || ! entityCls . _lazyInitCheck ( domElem [ 0 ] ) && ! params . lazyInit ) {
156+ if ( ignoreLazyInit || params . lazyInit === false || ! entityCls . _checkLazyInit ( domElem [ 0 ] ) && ! params . lazyInit ) {
157157 ignoreLazyInit && domElem . addClass ( BEM_CLASS_NAME ) ; // add css class for preventing memory leaks in further destructing
158158
159159 entity = new entityCls ( uniqIdToDomElems [ uniqId ] , params , ! ! ignoreLazyInit ) ;
@@ -342,7 +342,7 @@ function getEntityBase(baseCls, entityName, base) {
342342}
343343
344344/**
345- * Extract lazyInit property from staticProps
345+ * Extract lazyInit property from static props
346346 * @param {Object } [staticProps]
347347 * @returns {?Boolean }
348348 */
@@ -359,20 +359,16 @@ function extractLazyInitProp(staticProps) {
359359/**
360360 * Processing lazyInit rules for entity
361361 * @param {Function } entity BemDomEntity
362- * @param {Object } [ mod] mod declaration
362+ * @param {Object } mod mod declaration
363363 * @param {Boolean } lazyInit lazyInit behavior
364364 * @returns {?Boolean }
365365 */
366366function processLazyInitRule ( entity , mod , lazyInit ) {
367- if ( arguments . length < 3 ) {
368- lazyInit = mod ;
369- mod = undef ;
370- }
371-
372- var rules = entity . _lazyInitRules || ( entity . _lazyInitRules = [ ] ) ;
367+ var rules = entity . _lazyInitRules ;
373368
374369 rules . push ( {
375- check : mod ? entity . _buildModValRE ( mod . modName , mod . modVal ) : entity . _buildRE ( ) ,
370+ check : entity . _buildModValRE ( mod . modName , mod . modVal ) ,
371+ modName : mod . modName ,
376372 lazyInit : lazyInit
377373 } ) ;
378374}
@@ -864,15 +860,6 @@ var BemDomEntity = inherit(/** @lends BemDomEntity.prototype */{
864860 return this . getEntityName ( ) + MOD_DELIM + modName ;
865861 } ,
866862
867- /**
868- * Builds a regular expression for check entity on DOM element
869- * @private
870- * @returns {RegExp }
871- */
872- _buildRE : function ( ) {
873- return new RegExp ( '(\\s|^)' + this . getEntityName ( ) + '?(?=\\s|$)' ) ;
874- } ,
875-
876863 /**
877864 * Builds a regular expression for extracting modifier values from a DOM element of an entity
878865 * @private
@@ -914,18 +901,28 @@ var BemDomEntity = inherit(/** @lends BemDomEntity.prototype */{
914901 /**
915902 * Check domNode for lazy initialization entity
916903 * @protected
917- * @returns {?Boolean }
904+ * @param {HTMLElement } domNode
905+ * @returns {Boolean|undefined }
918906 */
919- _lazyInitCheck : function ( domNode ) {
920- var rules = this . _lazyInitRules , rule ;
921- if ( ! rules ) return null ;
907+ _checkLazyInit : function ( domNode ) {
908+ var rules = this . _lazyInitRules ,
909+ len = rules . length ,
910+ rule ,
911+ lazyInit ,
912+ modName ;
922913
923- var len = rules . length ;
924914 while ( rule = rules [ -- len ] ) {
925- if ( rule . check . test ( domNode . className ) ) return rule . lazyInit ;
915+ if ( modName !== rule . modName && rule . check . test ( domNode . className ) ) {
916+ if ( lazyInit === undef || lazyInit === true ) {
917+ modName = rule . modName ;
918+ lazyInit = rule . lazyInit ;
919+ }
920+
921+ if ( lazyInit === false ) return lazyInit ;
922+ }
926923 }
927924
928- return null ;
925+ return lazyInit !== undef ? lazyInit : this . lazyInit ;
929926 }
930927} ) ;
931928
@@ -940,6 +937,8 @@ var Block = inherit([bem.Block, BemDomEntity], /** @lends Block.prototype */{
940937 _block : function ( ) {
941938 return this ;
942939 }
940+ } , {
941+ _lazyInitRules : [ ]
943942} ) ;
944943
945944/**
@@ -953,6 +952,8 @@ var Elem = inherit([bem.Elem, BemDomEntity], /** @lends Elem.prototype */{
953952 _block : function ( ) {
954953 return this . _blockInstance || ( this . _blockInstance = this . findParentBlock ( getEntityCls ( this . __self . _blockName ) ) ) ;
955954 }
955+ } , {
956+ _lazyInitRules : [ ]
956957} ) ;
957958
958959/**
@@ -1026,12 +1027,7 @@ bemDom = /** @exports */{
10261027
10271028 base = getEntityBase ( Block , blockName , base ) ;
10281029
1029- var lazyInit = extractLazyInitProp ( staticProps ) ,
1030- entity = bem . declBlock ( blockName , base , props , staticProps ) ;
1031-
1032- lazyInit !== null && processLazyInitRule ( entity , lazyInit ) ;
1033-
1034- return entity ;
1030+ return bem . declBlock ( blockName , base , props , staticProps ) ;
10351031 } ,
10361032
10371033 /**
@@ -1054,12 +1050,7 @@ bemDom = /** @exports */{
10541050
10551051 base = getEntityBase ( Elem , entityName , base ) ;
10561052
1057- var lazyInit = extractLazyInitProp ( staticProps ) ,
1058- entity = bem . declElem ( blockName , elemName , base , props , staticProps ) ;
1059-
1060- lazyInit !== null && processLazyInitRule ( entity , lazyInit ) ;
1061-
1062- return entity ;
1053+ return bem . declElem ( blockName , elemName , base , props , staticProps ) ;
10631054 } ,
10641055
10651056 declMixin : bem . declMixin ,
0 commit comments