Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A model listening to other models? Yuck, that's just wrong. In an MVC application, only controllers should update models. Just because Backbone lets you listen to model events from anywhere doesn't mean it's a good idea.

IMHO Application events should simply bubble up through the DOM, and get caught by appropriate controllers (Backbone.View class in backbone parlance) that then modify the appropriate models. If need be it's the top-level controller for the app, eg:

document.body.addEventListener(function(e) { modelA.doSomething(e.data) modelB.doSomethingElse(e.data) });

I'd take a simple approach like that over an event bus/dispatcher/coolest-new-pattern-since-sliced-bread - any day, and sleep at night knowing if something happens to me, any employee will be able to parse and debug my code.

PS And no, I don't use Backbone, but my own 500 LOC MVC framework that's got zero dependencies and is about 100x faster.



Backbone is considered a high-quality javascript project, written by a very talented and experienced developer.

Could you explain what you do differently in your MVC framework to achieve those gains?


Easy - he doesn't support anybody else's requirements, app designs, or coding practices.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: