-
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
wrap() mutates bemjson which can lead to error for second run for same input data #495
Comments
The same issue with $ 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 |
Prob if we can't fix this, we can deny this. Actual BehaviorfirstTime: <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? 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
The text was updated successfully, but these errors were encountered: