Comments (11)
Undefined is undefined. You should not use it to prevent default values. Use null
instead.
from bh.
We used to use undefined
in BEMJSON
to drop values set in templates and it actually works fine in BEMHTML
. Don't you think we should support the same in BH
?
from bh.
No, I don't think so. You definitely should use null
to drop values.
Can you show me some examples of using undefined
?
from bh.
E.g.
attrs()(function() {
return {
someAttr: this.ctx.bla // where this.ctx.bla can be undefined
};
});
from bh.
@tadatuta если в this.ctx.bla
лежит undefined
, это равносильно пустому объекту.
Если в bemhtml не так, то это надо исправить.
from bh.
@mishanga в i-bem.bemhtml
для мержа результата выполнения моды attrs
с полем attrs
из bemjson
используется extend
, где проверяется hasOwnProperty
, так что если в bemjson окажется { attrs: { f1: undefined }
, а в шаблоне attrs()({ f1: 'bla' }), то в результирующий html f1
не попадет. ну и для меня это интуитивно ожидаемое поведение, если честно.
from bh.
@tadatuta получается, что ты кладешь в поле какое-то значение, которое переопределяет шаблон, а в конечный html не попадает. Это баг и сатанизм, на мой взгляд.
@veged @dfilatov коллеги, ваше мнение?
from bh.
у нас специально было сделано, что значение undefined
в attrs
означает отсутствие атрибута — поэтому, кажется логичным желание, передавая undefined
перетереть ранее установленный атрибут (хоть мы и не задумывали это)
но я не понял, почему оно не работает при extend
— hasOwnProperty
этож не typeof ... !== 'undefined'
и отдельно история про то, что от hasOwnProperty
надо везде отказаться
from bh.
@veged оно как раз работает при extend
, но в BH extend в этом месте не используется, отсюда и разное поведение BEMHTML vs BH.
from bh.
@veged чтобы удовлетворить логичное желание перетереть атрибут, можно передать null
.
from bh.
Поговорили с @veged, решили привести логику к естественной для JS, то есть учитывать поля, если они явно заданы, пусть даже и в значении undefined
. То есть сделать как в bemhtml.
Это надо не только в методе attrs исправить, я сделаю в ближайшие дни.
from bh.
Related Issues (20)
- Readme: describe `bh.toHtml()`
- block vs. block_mod apply bug (order matters!) HOT 6
- Need documentation on new global matcher feature
- jsElem
- jsAttr Defaults: `data-bem` name + `json` scheme HOT 7
- bh.require
- Documentation on escaping utils
- Proposal: ctx.if() HOT 5
- Add more examples for boolean attributes to README
- add tProxy shortcut
- Bug with ctx.js() HOT 6
- BH doesn't extend client 'js' param when it equal true HOT 3
- How to off escaping for .content() HOT 4
- Демо не работает в Firefox
- tParam rewrites value from previous level HOT 2
- How to achieve a bemhtml replace() like behaviour? HOT 7
- Option to drop trailing slashes for short tags
- Remove eval from runtime HOT 2
- What about escaping specific BEMJSON field, e.g. 'contentSafe'? HOT 14
- Матчинг на элемент по модификатору блока HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bh.