bem / bem-core

BEM Core Library
https://ru.bem.info/technologies/classic/i-bem/
Other
275 stars 94 forks source link

i-bem.bemhtml: Think about helpers to modify fields in bemjson #738

Open narqo opened 9 years ago

narqo commented 9 years ago

We have a lot of stuff like:

1.

(item.mods || (item.mods = {})).myMod = 'myVal';

2.

mix()(function() {
  var mix = ctx.mix,
    newMix = apply('mix');

  if(mix) {
    newMix = [mix].concat(newMix);
  }

  return newMix;
});
qfox commented 9 years ago

For (1):

ctx.mod('myMod', 'myVal'); // bh.js

So it will be nice if we would have:

this.ctx.mod...
narqo commented 9 years ago

@zxqfox the problem is more generic, because item in example above, could be any object from context (e.g. item = json.items[1] in bh terms).

For the case you showed, you should use this.mods.myMod = 'myVal'.

qfox commented 9 years ago

Oh, you mean while creating bemjson node on the fly. Then something like item = ctx.makeNode(item); that will create mods and probably other standard fields.

Proposal for the second:

// (1)
mix()(function() {
  return (ctx.mix || []).concat(apply('mix'));
})

or if ctx.mix will be prefedined as standard bemjson node field with default value []:

// (2)
mix()(function() {
  return ctx.mix.concat(apply('mix'));
})

or a real helper...

veged commented 9 years ago

for mixes: #820