Open tadatuta opened 6 years ago
The same issue with extend()
:
$ cat extend.js
const bemhtml = require('./').bemhtml;
const tmpl = bemhtml.compile(function() {
block('b1').extend()({ 'ctx.content': 42 });
});
const bemjson = { block: 'b1' };
const firstTime = tmpl.apply(bemjson);
console.log('firstTime:', firstTime);
console.log(bemjson);
const secondTime = tmpl.apply(bemjson);
console.log('secondTime:', secondTime);
console.log(bemjson);
$ node extend.js
firstTime: <div class="b1">42</div>
{ block: 'b1', content: undefined }
secondTime: <div class="b1"></div>
{ block: 'b1', content: undefined }
@tadatuta I see only one solution: copy bemjson to a new object in first line of bemhtml.apply()
. Is it OK?
Prob if we can't fix this, we can deny this.
firstTime: <div class="b2"><div class="b1"></div></div>
secondTime: Exception with xjst can't go in to the same river twice
Probably we can generate some id for the xjst passes on the apply call and use it for _wrap flag? Cuz cloning objects is a thing we don't want to do because of speed.
Or create an ctx with a Set of used wrappers and extends for a node (object) in a bemjson tree (invert the structure) to prevent mutations of bemjson at all.
Guess, right now we have the same thing with deeper placed objects:
it('should work with several apply() calls', function() {
var bemjson = [ { tag: 'span', content: { block: 'b1' } } ];
var expected = '<span><div class="b1">42</div></span>';
var tmpl = fixtures.compile(function() {
block('b1').extend()({ 'ctx.content': 42 });
});
assert.equal(
tmpl.apply(bemjson),
expected,
'first apply() call returns not expected value'
);
assert.equal(
tmpl.apply(bemjson),
expected,
'second apply() call returns not expected value'
);
});
Any news here?
Input code or something about issue background
Important!
Expected Behavior
Actual Behavior
Your Environment
Any version of
bem-xjst
withwrap()
support.// cc @vithar