News for hackers. Stuff that matters.
Re:Hello Backbone.js - A step-by-step tutorial by oscilloscope on Tuesday June 07, 2011 @09:59AM (#2629121)
This is exactly what it feels like to build Backbone interfaces!

Definitely would give someone a leg up learning for the first time, compared to the Todos app. Plus it doesn't have anti-patterns like `this.model.view = this`, a line which Yehuda Katz actually mocked at a recent SproutCore meetup.

Re:Hello Backbone.js - A step-by-step tutorial by jashkenas on Tuesday June 07, 2011 @10:12AM (#2629172)
Out of curiosity, what did Mr. Katz say about setting a reference from the model to the view at the meetup?
Re:Hello Backbone.js - A step-by-step tutorial by oscilloscope on Tuesday June 07, 2011 @06:19PM (#2631148)
He had led in to a section on "Other MVC Frameworks". Then a single slide with some code along these lines:

  Todo = OtherMVC.Model.extend({
    clear: function() { this.view.remove(); }
  });

  TodoView = OtherMVC.View.extend({
    initialize: function() { this.model.view = this; }
  });
Basically he ragged on that for breaking MVC, and never mentioned Backbone by name. I spoke to him afterwards, and he seemed pretty set against Backbone. He considers manually bubbling events to be tedious: "not the happy path".

I've been inspired by Morphic recently, where models having knowledge of their views makes sense. When I was a beginner though, I was briefly puzzled by how to connect multiple views to a model and vice versa: I first tried to extend the pattern above before binding to model events.

Re:Hello Backbone.js - A step-by-step tutorial by swah on Tuesday June 07, 2011 @08:59PM (#2631618)
I thought loose coupling was a feature.
Re:Hello Backbone.js - A step-by-step tutorial by ambertch on Tuesday June 07, 2011 @11:55PM (#2631961)
lol! I saw the same at another recent meetup. Damn, Katz really doesn't like Backbone...
Re:Hello Backbone.js - A step-by-step tutorial by tialys on Tuesday June 07, 2011 @10:17AM (#2629188)
As someone who's just getting started with Backbone, I'd be very interested to see that talk, and here suggestions for what to do instead of 'this.model.view = this'.
Re:Hello Backbone.js - A step-by-step tutorial by StavrosK on Tuesday June 07, 2011 @10:27AM (#2629228)
If Spine is anything to go by, you bind events from the view to the model and then trigger them from your code on the model instance.
Re:Hello Backbone.js - A step-by-step tutorial by jashkenas on Tuesday June 07, 2011 @10:47AM (#2629314)
Usually that's the case -- but if you know for certain that there's a one-to-one relationship between a model and it's view, then there's no harm in having a direct reference for convenience. Pragmatism > Purity, where UI code is concerned.
Re:Hello Backbone.js - A step-by-step tutorial by StavrosK on Tuesday June 07, 2011 @10:50AM (#2629329)
I agree with you. I'm concerned about memory leaks from the circular references, though.
Re:Hello Backbone.js - A step-by-step tutorial by jashkenas on Tuesday June 07, 2011 @11:02AM (#2629379)
Circular references are garbage collected -- no need to worry about them.

You might be thinking of a terrible old IE bug where circular references between JavaScript objects and DOM nodes were never collected, but that's never been an issue with JavaScript-only references.

Re:Hello Backbone.js - A step-by-step tutorial by StavrosK on Tuesday June 07, 2011 @11:48AM (#2629589)
Oh, I didn't know that. That alleviates many of my concerns, then, thank you.
Re:Hello Backbone.js - A step-by-step tutorial by joubert on Wednesday June 08, 2011 @07:31AM (#2632701)
The Responder pattern used in SproutCore (inspired by Cocoa) is very elegant.