Closed a-x- closed 8 years ago
@a-x- what kind of stuff you named “service stuff”?
Are you read documentation? In this section explained in detail about semantics of this
fields and this.ctx
.
Feel free to reopen this discussion if something not clear.
Thank you, I haven't seen above linked documentation page earlier
Recently i dramatically improve my xjst understanding, and i know about this.ctx.mods and this.mods, for example today.
I'll read doc too soon.
any way, this.ctx.someParam
, is uses more frequently than this.something
as i see.
Am I right?
for example in our project:
ALL_THIS=$(ag -Gbemhtml 'this\.' | wc -l);
THIS_CTX=$(ag -Gbemhtml 'this\.ctx' | wc -l);
node -p "(($ALL_THIS - $THIS_CTX) / $ALL_THIS * 100).toFixed(2) + '%'"
this.something not this.ctx.someParam
:
9.31%
this.ctx.someParam
:
~ 90%
What do not you like? That this.ctx.prop
is longer than this.prop
? We can’t merge this.ctx fields and this fields because it’s different objects.
@a-x- we can’t change API as you suggest in issue title. Because of this case:
{
block: 'example',
ctx: { something: 'wrong' },
reapply: 'oh, my',
isSimple: 'etc'
}
block('example').def()(function() {
var html = this.reapply({ block: 'reapply-me' });
…
return this.isSimple('test');
})
But I have good news for you: take a look at https://github.com/bem/bem-xjst/pull/200
After merge you can write templates:
// BEMJSON: { block: 'b', prop: 'bar' }
// Template:
block('b').def()(function(_, ctx) {
return ctx.prop; // 'bar'
});
cool
there is crazy non-realistic idea...
move service stuff in something like
this._
, because its are used rarely. and move block'sparams
fromthis.ctx
tothis
, because its are used frequently