bem / bem-xjst

bem-xjst (eXtensible JavaScript Templates): declarative template engine for the browser and server
https://bem.github.io/bem-xjst
Other
115 stars 47 forks source link

BEMTREE: bug with applyNext({'ctx.js':'test' }) #181

Closed tadatuta closed 7 years ago

tadatuta commented 8 years ago
var BEMHTML =  require('./bundle');

BEMHTML.compile(function() {
    block('b1').def()(function() {
        var r = applyNext({ 'ctx.blah': 'ololo' });
        console.log(r);
        return r;
    });

    block('b1').content()(function() { return this.ctx.blah;  });
});

BEMHTML.apply({ block: 'b1'  }); // { block: 'b1', blah: undefined, content: 'ololo' }

blah equals undefined here.

I understand that bem-xjst tries to rollback the state after it went out of local and for performance reason does not delete context keys but just assign them to undefined but it still isn't quite intuitive.

qfox commented 8 years ago

tadatuta commented 8 years ago

Let's consider real life use case.

If we have BEMHTML template, we can go with

block('b1').def()(function() { return applyNext({ 'mods.m1': 'blah' }); });

and get <div class="b1 b1_m1_blah"></div> which is exactly what was expected.

And if we move the same template to BEMTREE, it will actually apply all the templates for b1_m1_blah (if present) but won't add m1 modifier and as so we'll just get <div class="b1"></div> as a result.

qfox commented 8 years ago

Yeah, it looks like a critical thing for bemtree.

miripiruni commented 8 years ago

It look like won’t fix.

I think mods.m1 is kind of hack which you do not want use. And why you want apply b1_m1_blah but won’t add modifier?

tadatuta commented 8 years ago

I don't know why mods.m1 is a hack but still think current implementation far from intuitive.

PS: The issue was created as a result of a bug in real project code (and it took quite a while to understand what's going on there).

tadatuta commented 8 years ago

I just was asked why

block('bla').def()(function() {
    return applyNext({ 'ctx.js': { bla: 1 } });
});

is not working in BEMTREE.

Still think it's a bug.

miripiruni commented 8 years ago

I Agree. Bug.

Template:

block('b').def()(function() {
    return applyNext({ 'ctx.js': { bla: 1 } });
});

BEMJSON:

{ block: 'b' }

BEMTREE result:

{ block: 'b', js: undefined }
tadatuta commented 7 years ago

this is quite annoying when using extend mode :(

miripiruni commented 7 years ago

@tadatuta can’t reproduce in v8.x

miripiruni commented 7 years ago

Fixed in v8.5.0 via commit https://github.com/bem/bem-xjst/commit/70cfeb51c6#diff-a30c5c85232865c509b331edfca9e65bR43