Re:Avoiding Event Chains in Single Page Applications
by swah on Sunday August 31, 2014 @07:59PM
(#8250930)
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?
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.