Skip to content
This repository has been archived by the owner on Jan 13, 2018. It is now read-only.

Add ability to write level config module as a function (closes #364, BEM-931) #430

Merged
merged 2 commits into from
Sep 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/level.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,22 @@ var PATH = require('./path'),
LOGGER = require('./logger'),
isRequireable = bemUtil.isRequireable,

BEM,

// Use this as a function because of circular dependency which occurs
// if require is placed in the global scope of the module. BEM is also cached
// in a var to avoid require call every time (which is much slower than if statement.
getBem = function() {
if (!BEM) BEM = require('..');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У require же свой кеш есть.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я знаю, не стал полагаться на то что он такой же легкий.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проверил: действительно твой вариант гораздо быстрее.


return BEM;
},

getLevelClass = function(path, optional) {
var level = optional && !isRequireable(path) ? {} : requireLevel(path);

if (typeof level === 'function') level = level(getBem());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Напиши в комментариях в коде суть решения с getBem(). Я её понимаю, но кто-то при свежем взгляде в код может не понять.


if (level.Level) return level.Level;
return INHERIT(level.baseLevelPath? getLevelClass(level.baseLevelPath) : Level, level);
},
Expand Down
61 changes: 31 additions & 30 deletions test/data/make/project/pages/.bem/level.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
var BEM = require('../../..'),
PATH = require('path'),
extend = BEM.util.extend,
module.exports = function(BEM) {

BEM_TECHS = '../../bem-bl/blocks-common/i-bem/bem/techs',
PRJ_TECHS = '../../.bem/techs';
var PATH = require('path'),
extend = BEM.util.extend,

exports.getTechs = function() {
BEM_TECHS = '../../bem-bl/blocks-common/i-bem/bem/techs';

return {
'bemjson.js': '',
'deps.js': 'v2/deps.js',
'js': 'v2/js-i',
'css': 'v2/css',
'ie.css': 'v2/ie.css',
'i18n': PATH.join(BEM_TECHS, 'v2/i18n.js'),
'i18n.js': PATH.join(BEM_TECHS, 'v2/i18n.js.js'),
'bemhtml': PATH.join(BEM_TECHS, 'v2/bemhtml.js'),
'html': PATH.join(BEM_TECHS, 'html.js')
getTechs: function() {

return {
'bemjson.js': '',
'deps.js': 'v2/deps.js',
'js': 'v2/js-i',
'css': 'v2/css',
'ie.css': 'v2/ie.css',
'i18n': PATH.join(BEM_TECHS, 'v2/i18n.js'),
'i18n.js': PATH.join(BEM_TECHS, 'v2/i18n.js.js'),
'bemhtml': PATH.join(BEM_TECHS, 'v2/bemhtml.js'),
'html': PATH.join(BEM_TECHS, 'html.js')
};
},

getConfig: function() {

return extend({}, this.__base() || {}, {

bundleBuildLevels: this.resolvePaths([
'../../bem-bl/blocks-common',
'../../bem-bl/blocks-desktop',
'../../blocks'
])

});
}
};

};

exports.getConfig = function() {

return extend({}, this.__base() || {}, {

bundleBuildLevels: this.resolvePaths([
'../../bem-bl/blocks-common',
'../../bem-bl/blocks-desktop',
'../../blocks'
])

});

};