robodisco
robodisco

Reputation: 4272

Backbone - How to design for situation involving duplicate models

Take this hypothetical app where you can view contact information for all your friends on a social network.

Search for one friend and a contact card is displayed in the results. Within a contact card is the friends name but also links to all their friends. If you click one of those links the relevant contact card is prepended to the results. This allows you to drill through.

Normally just creating a collection of friends and an associated resultsView to orchestrate would suffice. Each model can hold an instance to its own view. But in this situation its possible for a duplicate model to be introduced. Ie.

Adam to=> Paul back_to=> Adam (adam would be in pauls friends list due to reciprocal friendship).

Perhaps im trying to force a visual design onto collections of models but collections do offer events out of the box (which are great for handling appending and removal of cards from the results). Im probably overthinking this but since im fairly novice at backbone cant figure it out.

Whats the best approach here?

Upvotes: 2

Views: 413

Answers (1)

tkone
tkone

Reputation: 22728

You might have a look at either Pathable's supermodel or Backbone-Relational.

Both are mixin/add-ons for the model/collection system within Backbone to prevent duplicative data in the way (I believe) you are describing.

I prefer supermodel a little more because it feels a little cleaner from an API perspective.

Upvotes: 1

Related Questions