-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Number mods values #165
base: master
Are you sure you want to change the base?
Conversation
@remnev @truerenton |
👍 Yeah, looks like it should. |
https://github.com/bem/bh/blob/master/lib/bh.js#L822-L831 To fix that you need: if (decl.elemMod) {
conds.push(
'json.elemMods && json.elemMods["' + decl.elemMod + '"] === ' +
- (decl.elemModVal === true || '"' + decl.elemModVal + '"'));
+ (decl.elemModVal === true || Number(decl.elemModVal) || '"' + decl.elemModVal +
}
if (decl.blockMod) {
conds.push(
'json.mods && json.mods["' + decl.blockMod + '"] === ' +
- (decl.blockModVal === true || '"' + decl.blockModVal + '"'));
+ (decl.blockModVal === true || Number(decl.blockModVal) || '"' + decl.blockModVal + '"'));
} Or something similar. |
I'll be fixing, ok? |
@@ -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 + '"')); |
There was a problem hiding this comment.
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 + '"'));
Так будет правильнее и быстрее по производительности.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String(true) === 'true'
— не страшно? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему так быстрее? у тебя новый вызов в рантайме, а у юры при генерации
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а примерно понятно
UPD: ой нет )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А, стоп. У меня кривой код.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String(true) === 'true' — не страшно? :-)
страшно ведь, так и произойдет
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, про производительность наврал.
В целом задача выглядит синтетической. В приведенном примере не может быть больше 7 значений модификатора, и их можно выразить через |
Если говорить о конкретном блоке, то я не захотел писать как ты, а написал 7 шаблонов для каждого модификатора чтобы не генерировать название тега и случайно на такое наткнулся. Лично мне показалось абсолютно безобидным то, что значение модификатора является числом |
see details in commit
The modifier serializes to class well, but template does not match