bem / bem-core

BEM Core Library
https://ru.bem.info/technologies/classic/i-bem/
Other
276 stars 95 forks source link

i-bem-dom: Rethink events #394

Closed veged closed 9 years ago

veged commented 10 years ago

Right now there are too many ways to use bem-events (directly and indirectly). We should rethink API.

Current state

dfilatov commented 10 years ago

Proposal

Proposal 2

Unify ALL events (BEM/DOM, live/instance). Pros:

Cons:

BEM

For instances
For classes

DOM

For instances
For classes
L0stSoul commented 10 years ago

hi!

MyBlock.whenInside(AnotherBlock, 'click', ...) -bind to all instances of MyBlock inside all instances of AnotherBlock introduce MyBlock.whenWith(AnotherBlock, 'click', ...) -- bind to all instances of MyBlock which placed on the same DOM-node as instances of AnotherBlock

I think such methods really dangerous because it's introduce a strogner dependencies between blocks. in such cases better use mods i think.

But, proposal two looks really nice. thx.

veged commented 10 years ago

We doesn't introduce any new ways for make strong dependencies between blocks — we just propose new (more clean) API for ways that already exists.

L0stSoul commented 10 years ago

IMHO

yeah you can do things like this right now. But it would be look ugly, and you may know that you do something dangerous, or wrong.

Clean built-in method for this purpose tell us - oh it's ok! do things like this. know you parents, do different thing depending on in wchich parent you are. it's perfectly normal.

And in general it's not.

veged commented 10 years ago

I believe that strategy for safe from produce not unambiguous code is not "ugly API" but educate about pros and cons ;-)

qfox commented 10 years ago

@L0stSoul Just to clarify. Please can you propose some "good API" for this? Probably you are right at some points.

qfox commented 9 years ago

I've stuck at re-emitting event and thinking about rewriting target with current element(elemInstance) or block.

function onSubblockEvent(e, data) {
  // some data fills
  this.emit(e, data); // here we can place some property with a link to this
}

It's pretty similar to target, relatedTarget, originalTarget but in blocks/elements terminology.

narqo commented 9 years ago

Done with #977. The final API is: