Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/bh.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,12 +822,12 @@ BH.prototype = {
if (decl.elemMod) {
conds.push(
'json.elemMods && json.elemMods["' + decl.elemMod + '"] === ' +
(decl.elemModVal === true || '"' + decl.elemModVal + '"'));
(decl.elemModVal === true || Number(decl.elemModVal) || '"' + decl.elemModVal + '"'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо не декларацию к числу приводить, а значение модификатора в bemjson к строке:

'json.elemMods && String(json.elemMods["' + decl.elemMod + '"]) === ' +
    (decl.elemModVal === true || '"' + decl.elemModVal + '"'));

Так будет правильнее и быстрее по производительности.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String(true) === 'true' — не страшно? :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему так быстрее? у тебя новый вызов в рантайме, а у юры при генерации

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а примерно понятно

UPD: ой нет )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А, стоп. У меня кривой код.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String(true) === 'true' — не страшно? :-)

страшно ведь, так и произойдет

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, про производительность наврал.

}
if (decl.blockMod) {
conds.push(
'json.mods && json.mods["' + decl.blockMod + '"] === ' +
(decl.blockModVal === true || '"' + decl.blockModVal + '"'));
(decl.blockModVal === true || Number(decl.blockModVal) || '"' + decl.blockModVal + '"'));
}
res.push('if (' + conds.join(' && ') + ') {');
pushMatcher(res, fn.__id, decl.index);
Expand Down
19 changes: 19 additions & 0 deletions test/test.match.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,23 @@ describe('bh.match()', function() {
'<div class="button"><div class="button__control"></div></div>'
);
});

it('should match on Number mod values', function() {
bh.match('title', function(ctx) {
ctx.tag('h1');
});

bh.match('title_level_2', function(ctx) {
ctx.tag('h2');
});

bh.apply({
block: 'title',
mods: {
level: 2
}
}).should.equal(
'<h2 class="title title_level_2"></h2>'
);
});
});