Skip to content

Backbone styles and tips

Jamie Alexandre edited this page Aug 30, 2014 · 3 revisions

Principles

  • Views encapsulate a portion of the DOM, and handle all user interactions with that part of the DOM. Be sure to scope any jQuery references to the current view (this.$(".have-some-class") or this.$el.html("...")) to avoid cross-view interference.
  • Models serve as the canonical representation of state. Avoid storing app state in the DOM, in the view itself, or in global variables. State lives in the models, and views listen to the models to update the DOM when the state they care about changes. Similarly, when a user interaction needs to change state, it should do so by setting a value on a model. Other views can then respond to the state change as needed.
Clone this wiki locally