sbmaxx / bem-priv Goto Github PK
View Code? Open in Web Editor NEWUse the power of inherit.js to generate BEMJSON with BEMPRIV blocks
Use the power of inherit.js to generate BEMJSON with BEMPRIV blocks
do you want move bem-priv repo to bem organization?
Need more information in https://github.com/sbmaxx/bem-priv/blob/develop/packages/bem-priv/src/bempriv.js#L499
For example: block name whose declaration doesn`t exist
Will be helpfull
По аналогии с .prop()
, только несколько атрибутов за раз.
Now, if I need to return empty value instead of block in some cases, I have to write some redundant code:
// old implementation using "blocks"
blocks['my-block'] = function(data) {
if (!data.myData) return '';
return { blocks: 'my-block', content: data.myData };
}
// "bempriv" implementation
BEMPRIV.decl('my-block', {
init: function() {
if (!this.data.myData) return;
this.content(this.data.myData);
},
bemjson: function() {
if (this.data.myData) {
return this.__base();
}
}
}
Probably, it worth to implement some way to reach that without overloading bemjson method.
Declarations are easy
BEMPRIV.decl({ block: 'block', modName: 'mod', modValue: 'value' };
But what about creation? We have at least two popular approachs to create block:
BEMPRIV.create('block');
BEMPRIV.json('block'); // alias for BEMPRIV.create('block').bemjson();
The default __constructor
accept two parameters data, params
.
We have to choose new API for __constructor
and BEMPRIV.create
.
Было бы круто, если этот код работал бы =):
stubBlock = function(name, fn) {
var stub;
beforeEach(function() {
stub = blocks[name]
? sinon.stub(blocks, name, fn)
: BEMPRIV.stub(name);
});
afterEach(function() {
blocks[name]
? stub.restore()
: BEMPRIV.restore(name);
});
}
ну или типа того. В общем, хорошо бы, если можно было бы стабать BEMPRIV блоки.
for example:
BEMPRIV.json({block: 'lol', modName: 'type', modVal: 'cool'}, data, {});
Например, если надо добавить какое-то свойтво в mods, то надо писать так:
this.mods(_.assign(this.mods, { newProp: value });
Хорошо бы какой-нибудь хелпер для таких ситуаций, ну или прокачать mods()
, чтобы он понимал, что надо расширить объект, а не заменять его.
Судя по коду — https://github.com/sbmaxx/bem-priv/blob/develop/src/bempriv.js#L261 — поддержка миксинов есть, но не нашел примеров в тестах или еще где. Хорошо бы добавить примеров использования этой фичи.
We need this BEMJSON:
{
block: 'one',
title: 'we need custom props'
}
Code:
BEMPRIV.decl('one', {
init: function() {
this._property('title', undefined, 'we need custom props');
}
});
It would be great to write:
BEMPRIV.decl('one', {
init: function() {
this.title('we need custom props');
}
});
На данном коде bempriv выпадает с ошибкой
BEMPRIV.decl({
block: 'direct',
modName: 'serp-list',
modVal: 'yes'
}, {
init: function() {
return '';
},
test: function() {
}
});
var priv = BEMPRIV.create({ block: 'direct', mods: { 'serp-list': 'yes' } });
priv.test();
Ошибка:
return this._bemjson[prop][key];
^
TypeError: Cannot read property 'serp-list' of undefined
Отваливается здесь:
deepProp : function(prop, key, value) {
if (typeof this._bemjson[prop] === 'undefined') {
this._bemjson[prop] = {};
}
if (typeof value === 'undefined') {
return this._bemjson[prop][key]; \\ Отваливается тут
}
this._bemjson[prop][key] = value;
return this;
}
Как я понял bempriv пытается найти модификатор, указанный при декларации, в bemjson. Но в данном конкретном случае bemjson равен пустой строке, потому что init возвращает пустую строку.
BEMPRIV -> BP
with backward compatible.
bempriv.json();
instead of BEMPRIV.json();
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.