Filtering collections is fundamental to most Backbone applications. This is generally done within the context of a view. The view needs to display some subset of the collection. It selects the models it needs, by calling the where()
method on the collection. This gives us an array of model elements. However, the downside with where()
is that once you call it, you're now working with an array of models — not a collection of models.
Wednesday, July 2, 2014
Filtering Models When Cloning Backbone Collections
Friday, February 28, 2014
Fetching Backbone Models The Safe Way
If you're using Backbone, odds are that you have several detail views for various types of objects. Before those views are rendered, you need to ensure that model has been fetched. Otherwise, you don't have anything to render, besides the template, perhaps with placeholders filling in for the real model data. Or maybe your application has already performed a fetch on the collection, in which case, we have all the data required to render the detail view of the model. But, unless you're keeping that collection synchronized, you could be rendering stale data.
Friday, January 24, 2014
Backbone Collection Fetch Scheduler
It's tricky to properly manage the the fetching of several Backbone collections in a given application. There are factors at play that require close attention. We don't want to put too much load on the server. We don't want to put too much load on the client. We need to consider things such as concurrency, and the ability to prioritize based on collection freshness. This seems like a lot to take on, and it maybe overkill to worry about such matters in smaller applications. But as the sheer volume of collections grows, as the complexity between the collection relationships increases, you're going to need some sort of fetch scheduling strategy.
Friday, November 29, 2013
Two Approaches To Using Lodash Reduce
_.reduce()
— both have their upsides.