-
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
Support mod(m)
and elemMod(em)
without second argument
#346
Conversation
2721a93
to
7a48f32
Compare
block('a').mod('size', '*').mix()('sized'); | ||
``` | ||
Оба шаблона будут применены к узлам BEMJSON-а, у которых блок равен 'a' и | ||
присутствует модификатор 'size' (со значением отличным от `undefined`). |
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.
не только undefined
это отсутствие модификатора, а ещё и ''
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.
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.
Мы обычно пишем false везде.
looks ok |
7a48f32
to
34a6223
Compare
{ block: 'a', mods: { size: '', theme: 'dark' } } | ||
``` | ||
|
||
But templates will not applied for entities: |
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.
will not applied -> will not be applied
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.
@tadatuta OK
34a6223
to
288964c
Compare
@tadatuta thank you! 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.
Looks good at all. ;-)
@@ -123,6 +123,29 @@ The template are applied. Result: | |||
<small class="item item_size_1"></small> | |||
``` | |||
|
|||
If second argument of `mod()` was omited or equal is to '*' then templates with any |
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.
equal is to → equal to
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.
Fixed
@@ -123,6 +123,29 @@ The template are applied. Result: | |||
<small class="item item_size_1"></small> | |||
``` | |||
|
|||
If second argument of `mod()` was omited or equal is to '*' then templates with any | |||
value of modifier will be applied. |
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.
any value → any non-empty 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.
OK
block('a').mod('size').tag()('span'); | ||
block('a').mod('size', '*').mix()('sized'); | ||
``` | ||
Both templates will be applied to BEMJSON entities if block equals to 'a' and |
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 entities" is a strange thing. Do we declare it somewhere?
BEM entity is absolutely another thing.
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.
Fixed
block('a').mod('size', '*').mix()('sized'); | ||
``` | ||
Both templates will be applied to BEMJSON entities if block equals to 'a' and | ||
'size' modifier exists (with value not `undefined` or `''`). |
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.
equal neither to ... nor to ...
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.
Fixed
{ block: 'a', mods: { size: '', theme: 'dark' } } | ||
``` | ||
|
||
But templates will not be applied for entities: |
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.
Guess we should not use entities here. BEMJSON nodes or Nodes?
be applied for entities:
→ be applied to:
?
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.
Fixed
@@ -152,6 +176,10 @@ block('page').elem('content').elemMod('type', 'index').mix()({ block: 'mixed' }) | |||
|
|||
`elemModVal` проверяются на соответствие после приведения к строке. Это поведение аналогично поведению проверки `modVal`. | |||
|
|||
Второй аргумент `elemMods()` также может отстуствовать или быть равен '*', в |
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.
'*'
в бэктики?
@@ -152,6 +176,10 @@ block('page').elem('content').elemMod('type', 'index').mix()({ block: 'mixed' }) | |||
|
|||
`elemModVal` проверяются на соответствие после приведения к строке. Это поведение аналогично поведению проверки `modVal`. | |||
|
|||
Второй аргумент `elemMods()` также может отстуствовать или быть равен '*', в | |||
этом случае поведение аналогичное режиму `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.
почему здесь «узлам», а в англ. версии BEMJSON entities или entities? узлы лучше, и не противоречат key-concepts из методологии
@@ -117,12 +117,36 @@ block('item') | |||
<small class="item item_size_1"></small> | |||
``` | |||
|
|||
Если второй аргумент `mod()` отсутствует либо равен '*' тогда к узлу будут |
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.
звезду в бэктики?
for (var i = 0; i < this.keys.length - 1; i++) { | ||
val = val[this.keys[i]]; | ||
if (!val) | ||
return false; | ||
} | ||
|
||
if (this.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.
Технически, разницы с точки зрения шаблонизатора нет, но кажется, что лучше всё-таки использовать true
, а не '*'
, потому что консистентность с i-bem
onSetMod
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.
onSetMod
со значением модификатора true
это же не то что проверка подпредиката «есть такой модификатор»… Я могу убрать волшебное слово wildcard, но, мне кажется, лучше оставить специальное значение '*'
. Тогда можно будет явно писать mod('size', '*')
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.
Ну черт с ним тогда, но имхо это неконсистентность на уровне onSetMod, и нет смысла делать так же, как и там.
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('size', '*')» — таким образом у нас 2 способа добиться одного и того же. А зачем?
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 убрал.
@@ -83,5 +83,33 @@ describe('Modes .mod(modName, modVal)', function() { | |||
{ block: 'b', mods: { m: null } }, | |||
'<div class="b"></div>'); | |||
}); | |||
|
|||
it('should support mod with wildcard', function() { |
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.
очень лукаво называть специальное значение строка со звездой
вайлдкардом. Вайлдкард позволяет a*
, *a
, a*a
, ??pup
etc.
Github радует) |
9dd1d7b
to
354e587
Compare
Updated |
354e587
to
b32aab9
Compare
b32aab9
to
5f5221f
Compare
Fixed #274
Am I do it right?
//cc @veged @zxqfox