Skip to content

Instantly share code, notes, and snippets.

@phamd1989
Last active December 18, 2015 11:59
Show Gist options
  • Save phamd1989/5780002 to your computer and use it in GitHub Desktop.
Save phamd1989/5780002 to your computer and use it in GitHub Desktop.
Learning Backbone.js
1. Listen to changes in the model can be implemented through the initialize() by the following format: this.on('change', callback_function). Listen to changes of a specific attribute can be done through this way too (just add in what attribute after change: change -> change:attr_name)
2. validation through Model.validate()
3. View does not contain the HTML markup. It contains the logic behind the presentation of the model's data to the user.
4. A view’s render() method can be bound to a model’s change() event, enabling the view to instantly reflect model changes without requiring a full page refresh.
5. el - a reference to the DOM element which every view has
6. view.$el === $(view.el) and view.$(selector) === $(view.el).find(selector)
7. Note the use of return this in view.render()
8. How come this.model.bind('change', _.bind(this.render, this)); can update the view when the model changes. This here just refers to the view itself.
9. There are two types of events web can listen to: DOM events and events using the Event API.
There are two ways to bound a DOM event: by using events property or by using jQuery.on(). If using events property, then this refers to the View. Otherwise if using jQuery.on(), this refers to the handling DOM element of jQuery. Every DOM events callback is passed in an event
There are two ways to bound an event using the Event API: using on() or listenTo()
10. Model triggers an event -> Collection triggers an event -> an event is triggered on a model (kind of complex)
11. toggleClass(): doc says to add or remove a class, but it seems to turn on or off a class. Think of it as an array, adding or removing an item from it. For example, li class = "completed" -> li class = "completed editing"
12. How does the render() method in app view gets called when we add or delete a todo?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment