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

Match: check mods/elemMods subpredicates after it’s converting to strings #266

Merged
merged 1 commit into from
Jun 29, 2016

Conversation

miripiruni
Copy link
Contributor

@miripiruni miripiruni commented May 12, 2016

Fix #220

Benchmarks result within the error.

return false;
}

return val[this.keys[i]].toString() === this.value.toString();
Copy link
Member

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.

Copy link
Contributor Author

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! 👍

@miripiruni miripiruni force-pushed the issue-220__mod-types branch 2 times, most recently from 0f02d84 to 8ff4da7 Compare May 12, 2016 12:52
test(function() {
block('b').mod('m', 'true').tag()('span');
},
{ block: 'b', mods: { m: true } },
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zxqfox updated!

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

@qfox qfox May 12, 2016

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.

Copy link
Contributor Author

@miripiruni miripiruni May 19, 2016

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 никогда не означал вайлдкард, поэтому я не понимаю отчего ты предлагаешь это сделать.

Copy link
Member

Choose a reason for hiding this comment

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

Я понимаю, что это не так. И это не стыкуется с их семантикой. Забудь слово вайлдкард, он здесь не подходит, я привел его для примера обозначения наличия значения (любого).
В БЭМ modVal равный true не существовал до внедрения булевых модификаторов (год 2013-14). Но до сих пор они никак не описаны в методологии, так что спорить надо уходить в другое место.

Извини, видимо, я тороплю события.

Copy link
Member

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').

Copy link
Member

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/#Модификаторы — нужно просто сделать аналогично

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@veged создал #274

@miripiruni
Copy link
Contributor Author

Review needed.

cc @zxqfox @tadatuta @veged


if (
keyVal === undefined ||
keyVal === null ||
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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 :-\

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@veged updated.

@miripiruni miripiruni added this to the 7.0.0 milestone May 20, 2016
@veged
Copy link
Member

veged commented May 21, 2016

diff LGTM
what about benchmarks?

@miripiruni
Copy link
Contributor Author

@veged as I wrote in PR’s description: Benchmarks result within the error.

@veged
Copy link
Member

veged commented May 23, 2016

which error? o_0

@miripiruni
Copy link
Contributor Author

@veged «в пределах погрешности» :)

@miripiruni
Copy link
Contributor Author

miripiruni commented Jun 17, 2016

@veged Я проверил как устроен MatchNested. Он используется только для elemMods и mods. И будет использован в будущем только для тех подпредикатов, ключ которых явится массивом из двух элементов: 1) имя режима 2) значение ключа модификатора или аналогичное значение ключа этого подпредиката.

@veged
Copy link
Member

veged commented Jun 17, 2016

стоит всё-таки сделать как-то, чтобы одно из приведений к строке случалось только один раз

@miripiruni
Copy link
Contributor Author

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)));
Copy link
Contributor Author

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' }

@veged
Copy link
Member

veged commented Jun 20, 2016

now it's perfect 👍

@miripiruni miripiruni merged commit 079a5c8 into master Jun 29, 2016
@miripiruni miripiruni deleted the issue-220__mod-types branch June 29, 2016 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants