RailsCasts Pro episodes are now free!

Learn more or hide this

Ozkar's Profile

GitHub User: Ozkar

Comments by

Avatar

For those who are curious, the following are the types of events that can get triggered for fetch() if you decided NOT to do {reset:true}:

  • 'add' - this gets triggered for EACH NEW model (not already in collection)
  • 'change' - this gets triggered for EACH EXISTING model (already in the collection)
  • 'remove' - this gets triggered for EACH model thats no longer in the collection after the fetch()
Avatar

Hi,

If anyone is having trouble with the collection's 'reset' event not triggering after calling this.collection.fetch(), it's because as of v1.0, the fetch() function only triggers the 'reset' event if you add {reset: true} as an option.

So, that line in the Raffler.Router.Entries() initialize function should actually look like this:

coffee-script
initialize: ->
  @collection = new Raffler.Collections.Entries()
  @collection.fetch({reset: true})

This is from the backbone.js site (Linky):

" If you want to smartly update the contents of a Collection, adding new models, removing missing ones, and merging those already present, you now call set (previously named "update"), a similar operation to calling set on a Model. This is now the default when you call fetch on a collection. To get the old behavior, pass {reset: true}."

Hopefully, when you have some spare time (ha!), you could update this tutorial with that little tidbit =)

Thanks for all your tutorials, I have been learning a ton!