-
Notifications
You must be signed in to change notification settings - Fork 48
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
Match: check mods/elemMods subpredicates after it’s converting to strings #266
Conversation
return false; | ||
} | ||
|
||
return val[this.keys[i]].toString() === this.value.toString(); |
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.
Check please for passing null here.
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.
@zxqfox Oh, yeah! Thank you! 👍
0f02d84
to
8ff4da7
Compare
test(function() { | ||
block('b').mod('m', 'true').tag()('span'); | ||
}, | ||
{ block: 'b', mods: { m: 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.
@miripiruni Commented the wrong line, sorry. I'm about this one.
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.
@zxqfox updated!
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.
What you think about making true
value as a '*'
?
true
means modifier exists. If it doesn't care about modifier value then semantically it should match to any value, isn't it?
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.
@zxqfox First of all, it’s out of scope of this PR =)
The second: change the semantic of true
modVal is a big major change. For what reason we should do it?
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.
It's not, because you decide this is major.
true
means modifier exists. If it doesn't care about modifier value then semantically it should match to any value, isn't it?
That's why. Tell me why not now.
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.
Прошу меня извинить за то, что сразу не предоставил аргументов.
Потому что true обозначает наличие модификатора в любом значении.
Сейчас это не так. Пользователи когда пишут block('b').mod('m', true) имеют ввиду не вайлдкард, а конкретное значение — true. В БЭМ modVal равный 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.
Я понимаю, что это не так. И это не стыкуется с их семантикой. Забудь слово вайлдкард, он здесь не подходит, я привел его для примера обозначения наличия значения (любого).
В БЭМ modVal равный true не существовал до внедрения булевых модификаторов (год 2013-14). Но до сих пор они никак не описаны в методологии, так что спорить надо уходить в другое место.
Извини, видимо, я тороплю события.
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.
Кстати, пользователи пишут .mod('m', true)
по другой причине — просто они не могут писать .mod('m')
.
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.
про булевые («простые») модификаторы всё придумано и описано в i-bem.js — https://ru.bem.info/technology/i-bem/v2/i-bem-js-mods/#Модификаторы — нужно просто сделать аналогично
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.
8ff4da7
to
1ed16bc
Compare
|
||
if ( | ||
keyVal === undefined || | ||
keyVal === null || |
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.
why you need to check null
?
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.
Because null.toString()
will prevent execution. But it should not.
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.
why not use String(...)
then?
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.
I wish I could say that it is slowly but I can’t. jsperf.com is down :-\
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.
should be the same, actually
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.
@veged updated.
1ed16bc
to
f446ac3
Compare
diff LGTM |
@veged as I wrote in PR’s description: Benchmarks result within the error. |
which error? o_0 |
@veged «в пределах погрешности» :) |
@veged Я проверил как устроен MatchNested. Он используется только для elemMods и mods. И будет использован в будущем только для тех подпредикатов, ключ которых явится массивом из двух элементов: 1) имя режима 2) значение ключа модификатора или аналогичное значение ключа этого подпредиката. |
стоит всё-таки сделать как-то, чтобы одно из приведений к строке случалось только один раз |
f446ac3
to
ab83060
Compare
Updated. cc @veged |
@@ -340,11 +340,11 @@ Tree.prototype.mode = function mode(name) { | |||
}; | |||
|
|||
Tree.prototype.mod = function mod(name, value) { | |||
return this.match(new PropertyMatch([ 'mods', name ], value)); | |||
return this.match(new PropertyMatch([ 'mods', name ], String(value))); |
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.
JFYI: при построении дерева entities эта функция добавит к шаблону подпредикат mod
уже в виде { key: [ 'mods', 'modName' ], value: 'modVal' }
now it's perfect 👍 |
Fix #220
Benchmarks result within the error.