Skip to content

Commit

Permalink
Merge pull request #428 from bem/revert-exportApply-optimization@v7.x
Browse files Browse the repository at this point in the history
BEMXJST: Revert exportApply optimization
  • Loading branch information
miripiruni authored Mar 17, 2017
2 parents f398bdb + b9f9002 commit af0fb5e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/bemxjst/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ BEMXJST.prototype.exportApply = function(exports) {

exports.BEMContext = self.contextConstructor;

for (var i = 0; i < self.oninit.length; i++)
self.oninit[i](exports, { BEMContext: exports.BEMContext });
for (var i = 0; i < self.oninit.length; i++) {
// NOTE: oninit has global context instead of BEMXJST
var oninit = self.oninit[i];
oninit(exports, { BEMContext: exports.BEMContext });
}
};
12 changes: 12 additions & 0 deletions test/init-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,16 @@ describe('oninit', function() {
}
}, '[4.[3.[0.<div class="b1">][2.[1.<div class="b2">]</div>]</div>]]');
});

it('should use global object as `this`', function () {
test(function() {
oninit(function() {
this._something = { blah: 42 };
});
block('b1').replace()(function() {
/* global _something */
return _something.blah;
});
}, { block: 'b1' }, '42');
});
});

0 comments on commit af0fb5e

Please sign in to comment.