enb / enb-bemxjst

bem-xjst support for ENB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support BEMContext from exports

blond opened this issue · comments

See bem/bem-core#1099

Now we extend the definition of the basic templates with oninit. The BEMContext is available from context argument.

oninit(function(exports, context) {
    if(!context.BEMContext) {
        throw Error("Seems like you have no base templates from i-bem.' + this.getName() + '");
    }
    context.BEMContext.prototype.require = function(lib) {',
        return __bem_xjst_libs__[lib];
    };
});

In bem-core@v3 BEMContext wiil be available from exports argument only.

Can we write as such way?

oninit(function(exports, context) {
var BEMContext = context.BEMContext || exports.BEMContext;     
if(!BEMContext) {
        throw Error("Seems like you have no base templates from i-bem.' + this.getName() + '");
    }
    BEMContext.prototype.require = function(lib) {',
        return __bem_xjst_libs__[lib];
    };
});

I think yes.

I would have swapped exports and context:

var BEMContext = exports.BEMContext || context.BEMContext;

/cc @tadatuta

As for me — 🆗