emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.46k stars 4.21k forks source link

pass the current DOM object in every events #9351

Closed gitlovenotwar closed 9 years ago

gitlovenotwar commented 9 years ago

Hi,

Can it pass the current DOM object in every actions and events? Not only in the view, but also in the router and controller, or anything, since ember uses jquery to manipulate the DOM. This would be very helpful. Thanks.

endash commented 9 years ago

Needing this is a big code smell that you're not properly separating your concerns. Your router definitely shouldn't care about a DOM element, and your controller almost certainly shouldn't. Even a view, if properly broken down into components and custom views, should care very little about the actual element in play.

FWIW the ONLY time I've cared about DOM elements that I didn't explicitly create (as for instance a modal blocker) was when I needed a completely separate rendered view to track its location to match the trigger. Even then, the element was the main element for that view and was easily grabbed and passed to the action I was firing. Almost any other situation is more properly handled via a custom component or view.

gitlovenotwar commented 9 years ago

I see that it will takes some time 'IF' it will be implemented. Hmmm, Are you saying manipulation of DOM elements are not scoped on an ember app? What about the animations?(I'm not using css transition/animation on this one since I need the timing and complete).

Pardon my ignorance for I have been just coding pure jQuery and trying/investing my time on ember. Reading/learning on the ember docs are not helping me at all, and haven't seen a DOM manipulation either(because it was not intended, no?). Anyway, why it was not there in the first place? Any downside of having it?

Meaning to say, the needs to need the DOM element is wrong in the first place?

endash commented 9 years ago

The downside is it would allow and probably even encourage wholesale abandonment of proper separation of concerns. If you need to manipulate a DOM element, do it in the view. End of story.

endash commented 9 years ago

Imagine this. Someone clicking a button in your app might trigger an API call, which might trigger a database update, which then might trigger a stored procedure. It'd be crazy for any of those things to ever know "what button got hit" in the UI, right? It would mean your architecture was a massive mess. Ember apps are the same but on a smaller scale: each layer is responsible for its own concerns. If a route is concerning itself with concrete DOM elements, then it's reaching way into the architectural onion and inappropriately messing with the view layer. That's a recipe for disaster.

gitlovenotwar commented 9 years ago

So all of the manipulation of DOM in every route will be handled only in the view, right?. I see, that's make sense. Is the sequence or flow on ember app is this?

Model -> Templates -> Controllers -> Views -> Route?

stefanpenner commented 9 years ago

events get the event (which has the node), actions do not.