koblas
koblas

Reputation: 27088

Handling subset of objects

What is a good pattern for how to handle a subset of objects.

Say I've got a list of Lockers, inside each Locker is a set of Items. The UI is something akin to this - we're going to hope that the ASCII art makes in through.

Locker#1    |    Item #1 in Locker #2
Locker#2 ** |    Item #2 in Locker #2
Locker#3    |    Item #3 in Locker #2
            |    Item #4 in Locker #2
            |    Item #5 in Locker #2
            |    Item #6 in Locker #2
            |    Item #7 in Locker #2
            |    Item #8 in Locker #2
            |

Locker #2 is selected (active). What I've been doing is setting a callback when locker #2 is activated and then doing a ItemCollection.fetch({ data: { lid: LOCKER_ID }}) to fetch the subset of items that are ready for display. Which doesn't feel very backbone like.

What' the better approach -

Upvotes: 1

Views: 286

Answers (1)

fguillen
fguillen

Reputation: 38832

I think everything depends on the amount of your data.

But I don't see any problem fetching the items Collection every time the filter changes. I really feel it is as Backbone way :). And this solution works for both cases: a lot of data, and few data.

As an optimization step you can cache the Collections and create new ones every time the filter changes. So you can reuse and already fetched one if the User click back to an already visited filter.

But still this optimization step is adding distance between your User and the fresh data. The User should reload the whole application to refresh his cached Collections. Or... add more code to reset Collections every X seconds... start to be a hard way.

So, in my opinion: re-fetch the Collection every time the User changes the filter sounds nice for me.

Upvotes: 1

Related Questions