-
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
Docs: write about template arguments and arrow function (fix for #367) #370
Conversation
1 similar comment
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.
У меня пара вопросов:
- Достаточно ли этого описания для понимания что там передается? (кажется, что да)
- Что можно убрать, чтобы не отвлекать от второстепенного?
# Функции шаблонов | ||
|
||
Если тело шаблона является функцией, то вы можете использовать два параметра: | ||
1. контекст выполнения шаблона |
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.
не хватает ;
|
||
Если тело шаблона является функцией, то вы можете использовать два параметра: | ||
1. контекст выполнения шаблона | ||
2. текущий узел BEMJSON, на который сматчился шаблон. |
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.
/vikka-mode on
В случае, когда тело шаблона является функцией, она вызывается с двумя аргументами:
- контекст выполнения шаблона;
- узел BEMJSON, удовлетворяющий подпредикату
match
(или как он там называется по научному).
/vikka-mode off
* @param {Object} json | ||
*/ | ||
attrs()(function(context, json) { | ||
return … |
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.
лучше что-то конкретное {href: json.url}
* @param {Object} context | ||
* @param {Object} json | ||
*/ | ||
attrs()(function(context, json) { |
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.
Последний раз, когда мы обсуждали, мы пришли не к ctx, json
, а к node, ctx
, потому что во всех текущих шаблонах такое: function() { var ctx = this.ctx;
и this меняется на node, а ctx остается как есть.
Можно еще раз подумать
мне json вторым аргументом кажется более понятным, потому что bemjson/json, примерно близко, но я не целевая аудитория, я и так знаю что там передается, как не назови.
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.
Я по-прежнему за node
и ctx
.
Во-первых, потому что this.ctx
никуда не девается и будет очень странно, если название будет разное.
Во-вторых, если this.ctx
— это сокращение от «контекст», то очень странно, если первый аргумент тоже будет context
.
В-третьих, BEMJSON — это вообще ни разу не JSON и потому название json
только больше будет сбивать с толку.
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.
Я подумал, что нет особого смысла в этом споре. Ведь каждый разработчик сам волен именовать эти аргументы. Главное, чтобы все улавливали суть. Пусть в доке будет node
, ctx
. Вальсируем дальше =)
); | ||
``` | ||
|
||
Такие же параметры доступны в подпредикате `match()`. |
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.
Тело подпредиката match()
так же вызывается с этими параметрами
писать везде в таком стиле: | ||
|
||
```js | ||
match((ctx, json) => { return !context.mods.disabled && json.target; }) |
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.
{} не нужны, достаточно: (node, ctx) => (!node.mods.disabled && ctx.target)
|
||
```js | ||
match((ctx, json) => { return !context.mods.disabled && json.target; }) | ||
attrs()((ctx, json) => { … }) |
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.
addAttrs()((node, ctx) => ({href: ctx.url}))
block('link')( | ||
/** | ||
* @param {Object} context | ||
* @param {Object} json |
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.
Кажется, этот кусок jsdoc ничего не дает ;-(
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.
Убрал
Сам же и ответил. Молодец =)
Я специально добавил эту информацию после всего основного рассказа «что доступно в теле шаблона». Убирать не нужно, нужно пояснять на примерах, что я и сделал. |
71fd709
to
ddc2612
Compare
по смыслу — ок, по именам аргументов — не ок. |
ddc2612
to
8551260
Compare
Updated |
LGTM 👍 |
@tadatuta @zxqfox давайте согласуем сначала русскоязычную версию, а затем я добавлю перевод на английский, OK? Сейчас эта информация совсем не раскрыта в доке. Я решил срочно дополнить.