0

In most Backbone examples I've seen, the creator of a view also creates the model or collection and then binds it to the view when it is initialised.

For top level views that will always render the same model, is it bad practice to have the view load its own model (e.g. via a call to a data manager utility)? If so, why?

Alasdair McLeay
  • 2,572
  • 4
  • 27
  • 50
  • I guess there are exceptions to every rule, but a good rule of thumb is, your views DO NOT make models/collections, only binds to them. In other words; your view only uses the data is not in charge of it. Reason? Sanity! Same reason why you shouldn't make anonymous functions - its a slippery slope. – Javier Buzzi Jan 11 '16 at 14:21
  • If your view is sort of a stand alone functionality, making model/collection in it is fine. I do it all the time (in such scenarios) I don't see how its a bad practice. – T J Jan 11 '16 at 17:33
  • @JavierBuzzi let's say I have a feedback form as a view, or something similar that is completely independent of other parts of the application. Why should some other part of the application create the model for my feedback from..? That creates unnecessary coupling. I like to see my feedback form as a stand alone component that I can drop in anywhere. I don't see how that's insane .__. – T J Jan 11 '16 at 17:36
  • @TJ i hear you, and understand that scenario, i would agree with you then. but for the most part, i make my models/collections in the same scope as the views and just bind to them. Its easier to manage when the code gets in the thousands of lines. – Javier Buzzi Jan 11 '16 at 17:43

0 Answers0