These are chat archives for bem/talk

13th
Jul 2014
Alexander Orlov
@nitrok
Jul 13 2014 07:26

Hello. How to figure out what goes wrong in simple case.
1 Get latest project stub,
2 use code from http://ru.bem.info/articles/start-with-project-stub/ (yes, I know it is a little bit old),

$ bem create -l desktop.blocks -b page -T bemhtml
block('page').elem('body').match(!this._done)(
    content()(function() {
        this._done = true;
        return {
            elem: 'inner',
            content: applyNext()
        };
    })
)

and page content does not have inner div =((

Sergey Berezhnoy
@veged
Jul 13 2014 08:00
@nitrok try to define and use your own new block — doesit work?
Alexander Savin
@apsavin
Jul 13 2014 08:08

@nitrok at first, I think you need to write match(!this._done) as

match(function () { return !this._done})

At second, I think, you can just write like this:

block('page').def()(function () {
    var ctx = this.ctx;
    ctx.content = { block: 'inner', content: ctx.content };
    applyNext();
});
Sergey Berezhnoy
@veged
Jul 13 2014 08:54
@apsavin you does't need to wrap in function predicates for this directly, cause it can't fail — you only need to do such in cases like this._bla._bla where this._bla can be undefined sometimes
Alexander Savin
@apsavin
Jul 13 2014 08:58
@veged thanks, you are right.
Sergey Berezhnoy
@veged
Jul 13 2014 09:03

@apsavin if you gonna act like this with directly injection in input context you can broke a lot of things — for example, if you have input json:

{ block: 'page', content: { elem: 'body' } }

and then modify it with such templates you get json:

{ block: 'page', content: { block: 'inner', content: { elem: 'body' } }

where elem body no longer belongs to the block page but to the block inner

Sergey Berezhnoy
@veged
Jul 13 2014 09:23
@nitrok the reason of your problem is that we rewrite templates for page in bem-core https://github.com/bem/bem-core/blob/v2/common.blocks/page/page.bemhtml — so there is no more __body elem and you can act with content of page itself:
block('page').match(!this._done).content()(function() {
    this._done = true;
    return {
        elem: 'inner',
        content: applyNext()
    };
})
we also gonna up version of bem-xjst in coming soon minor release of bem-core — after that don't need to use guards like this._done any more
Alexander Orlov
@nitrok
Jul 13 2014 18:02
@apsavin @veged thanks!