enb / enb-bemxjst

bem-xjst support for ENB
Other
22 stars 19 forks source link

Support BEMContext from exports #78

Closed blond closed 9 years ago

blond commented 9 years ago

See https://github.com/bem/bem-core/issues/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.

tormozz48 commented 9 years ago

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];
    };
});
blond commented 9 years ago

I think yes.

I would have swapped exports and context:

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

/cc @tadatuta

arikon commented 9 years ago

As for me — :ok: