Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

golyshevd
Copy link

see details in commit

The modifier serializes to class well, but template does not match

+ expected - actual

      -<h1 class="title title_level_2"></h1>
      +<h2 class="title title_level_2"></h2>

@golyshevd
Copy link
Author

@remnev @truerenton

@qfox
Copy link
Member

qfox commented Oct 30, 2015

👍 Yeah, looks like it should.

@qfox
Copy link
Member

qfox commented Oct 30, 2015

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.

@remnev
Copy link

remnev commented Oct 30, 2015

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 + '"'));
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.

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

@golyshevd golyshevd changed the title Should bh match on mods with {Number} values? Support for Number mods values Oct 30, 2015
@mishanga
Copy link
Member

В целом задача выглядит синтетической. В приведенном примере не может быть больше 7 значений модификатора, и их можно выразить через ctx.tag('h' + (ctx.mod('level') || 1)).
Использование численных модификаторов почти всегда говорит о неправильной архитектуре блока.

@golyshevd
Copy link
Author

Если говорить о конкретном блоке, то я не захотел писать как ты, а написал 7 шаблонов для каждого модификатора чтобы не генерировать название тега и случайно на такое наткнулся. Лично мне показалось абсолютно безобидным то, что значение модификатора является числом

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants