Skip to content

Commit

Permalink
Merge f2d7eab into 0366c43
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-homyakov committed May 6, 2019
2 parents 0366c43 + f2d7eab commit 798ef93
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
lib/bem*/bundle.js
/node_modules/
npm-debug.log
/.idea/
/coverage/
/bench/bem-xjst-*/
/bench/dat-*/
30 changes: 24 additions & 6 deletions lib/bemhtml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,31 @@ BEMHTML.prototype.renderAttrs = function(attrs, ctx) {
return out;
};

var BEMHTMLSet = typeof Set !== 'undefined' ?
Set :
(function() {
var MiniSet = function() {
this._storage = {};
};

MiniSet.prototype.add = function(item) {
this._storage[item] = true;
};

MiniSet.prototype.has = function(item) {
return this._storage[item] || false;
};

return MiniSet;
})();

BEMHTML.prototype.renderMix = function(entity, mix, jsParams, addJSInitClass) {
var visited = {};
var visited = new BEMHTMLSet();
var context = this.context;
var js = jsParams;
var addInit = addJSInitClass;

visited[entity.jsClass] = true;
visited.add(entity.jsClass);

// Transform mix to the single-item array if it's not array
if (!Array.isArray(mix))
Expand Down Expand Up @@ -335,11 +353,11 @@ BEMHTML.prototype.renderMix = function(entity, mix, jsParams, addJSInitClass) {
addInit = block && !item.elem;
}

// Process nested mixes
if (!hasItem || visited[key])
// Process nested mixes from templates
if (!hasItem || visited.has(key))
continue;

visited[key] = true;
visited.add(key);
var nestedEntity = this.entities[key];
if (!nestedEntity)
continue;
Expand All @@ -360,7 +378,7 @@ BEMHTML.prototype.renderMix = function(entity, mix, jsParams, addJSInitClass) {

if (!nestedItem.block &&
!nestedItem.elem ||
!visited[classBuilder.build(nestedItem.block, nestedItem.elem)]) {
!visited.has(classBuilder.build(nestedItem.block, nestedItem.elem))) {
if (nestedItem.block) continue;

nestedItem._block = block;
Expand Down

0 comments on commit 798ef93

Please sign in to comment.