1

Working on a large GWT, makes me fall in love with MVP pattern that comes with GWT. Basically its a passive view, where a controller knows all the business logic, and the view is as dump as possible. The cool thing with this is that you can easily change your view and that you can run your unit test fast cause no DOM is involved.

I've read articles about backbone.js but it seems that there the whole logic is in the view and there is no real decoupling of view and business logic. But maybe I'm wrong.

So I wonder if there is a JavaScript library that has the same approach as GWT.

Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297
  • possible duplicate of [MVP pattern with Javascript framework?](http://stackoverflow.com/questions/1102215/mvp-pattern-with-javascript-framework) – Peter Knego Jun 11 '11 at 13:46
  • 1
    Have you tried [spine](http://maccman.github.com/spine/)? – Raynos Jun 11 '11 at 14:21
  • @peter Not really, there are a bunch of frameworks implementing the mvc/mvp pattern. But there is wide range on how this framework define the pattern. Just google for mvc and you will find a bunch of definitions. My question was on the passive view pattern, as the one in GWT. – Andreas Köberle Jun 11 '11 at 17:18
  • @Raynos, no, but I'll take look, thanks. – Andreas Köberle Jun 11 '11 at 17:20

1 Answers1

2

With backbone.js, Views can register for DOM events and do as much or as little as you prefer.

In the case where you are doing very little, you can reconstitute the DOM event into a backbone.js event where the controller that created the view is likely registered for that event. The controller would then provide the business logic on behalf of the view.

Controller business logic usually ends up being a change to a model or a collection of models for which the view is responsible. If the view has bound itself to 'change' events for the model or collection, then it can seamlessly refresh itself.

Following this pattern leaves a view only responsible for rendering and bubbling up relevant DOM events. Lesser DOM events which don't lead to business logic can and should just be handled within the view.

Bill Eisenhauer
  • 6,183
  • 2
  • 30
  • 28