knockout/knockout — pull request #1448 by ismell (2014-07-03 21:59:40+00:00)
Title: Update the array utilities to use the native methods

By using the native methods this opens up an interesting usecase. I was playing around with the component flow and was having a hard time because my View Models are created by the template engine. What I needed was a way for my Backbone collections and models to get passed in as parameters into my View Models.

viewmodel.js

var viewModel = {collection: ko.observable(new Backbone.Collection())}

template.html

After some digging around I found that if I just use the *native* methods in the array helpers everything else just works.

The last step was to hook onto the collections events so I wrote a quick extender that will do just that. https://gist.github.com/ismell/d4f977f2d7a4a86b9cb1

So now if I just extend my observable with trackCollectionChanges my views will correctly update whenever my backbone collection changes.

viewmodel.js

var viewModel = {
collection: ko.observable(new Backbone.Collection()).extend({'trackCollectionChanges': true})
}

Sorry for the long story...