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

Strange applyNext behavior #121

Closed sbmaxx closed 8 years ago

sbmaxx commented 8 years ago

I think this is about wrong b-page.bemhtml.js template from islands — http://pastebin.com/JFVfYR1D

Paste it into http://bem.github.io/bem-xjst/ and use this bemjson:

([{
    block: 'b-page'
},{
    block: 'b-page'
},{
    block: 'b-page'
},{
    block: 'b-page'
},{
    block: 'b-page'
},{
    block: 'b-page'
}]);

You will get:

<body class="b-page b-page__body i-ua i-ua i-bem" data-bem='{"i-ua":{}}'></body>
<body class="b-page b-page__body i-ua i-ua i-ua i-bem" data-bem='{"i-ua":{}}'></body>
<body class="b-page b-page__body i-ua i-ua i-ua i-ua i-bem" data-bem='{"i-ua":{}}'></body>
<body class="b-page b-page__body i-ua i-ua i-ua i-ua i-ua i-bem" data-bem='{"i-ua":{}}'></body>
<body class="b-page b-page__body i-ua i-ua i-ua i-ua i-ua i-ua i-bem" data-bem='{"i-ua":{}}'></body>

It can be easily repaired by merging mix mode in template to http://pastebin.com/2nY1Z1tm

sbmaxx commented 8 years ago

@veged @indutny

veged commented 8 years ago

looks like applyNext() returns mix previously modified through push :-/ but it should be new for each other b-page block instance

tadatuta commented 8 years ago

That's what we decided to be not a bug of bem-xjst in https://github.com/bem/bem-xjst/issues/92 so it should be fixed in templates.

veged commented 8 years ago

@tadatuta looks similar, but I think it's not the same because there is no another template for mix with static literally defined array

qfox commented 8 years ago

@veged After reading sources I don't see it's another bug:

  mix()([{elem: 'body'}]),
  // ...
  mix()(function () {
    var mix = applyNext() || [], ...;
    mix.push({block: 'i-ua'});
    // etc... 

Still the same reference to static array.

veged commented 8 years ago

hm... maybe it was already fixed when I look at islands code

qfox commented 8 years ago

@veged Yeah, sorry. Here is the link: https://nda.ya.ru/3R8AaW

arikon commented 8 years ago

Considered as won't fix because of error in templates.