5 ms·
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.
by oscilloscope 15y ago
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.
- jashkenas 15y agoOut of curiosity, what did Mr. Katz say about setting a reference from the model to the view at the meetup?
- oscilloscope 15y agoHe 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.
- tialys 15y agoAs 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'.
- StavrosK 15y agoIf 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.
- jashkenas 15y agoUsually 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.
- StavrosK 15y agoI agree with you. I'm concerned about memory leaks from the circular references, though.
- jashkenas 15y agoCircular 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.
- StavrosK 15y agoOh, I didn't know that. That alleviates many of my concerns, then, thank you.
- joubert 15y agoThe Responder pattern used in SproutCore (inspired by Cocoa) is very elegant.