Showing posts with label collection. Show all posts
Showing posts with label collection. Show all posts

Wednesday, July 2, 2014

Filtering Models When Cloning Backbone Collections

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.

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

The Lodash reduce() function is an elegant way to reduce your collections down to a single result. For example, to sum an array of numbers, to apply a more elaborate formula to a specific property on a collection of objects, etc. I've found myself using two different approaches with _.reduce() — both have their upsides.