backstopmedia / hubbub

Sample project for the book Developing a Backbone.js Edge
http://backstopmedia.github.com/hubbub/
21 stars 111 forks source link

Global model cache? #14

Closed afeld closed 11 years ago

afeld commented 11 years ago

We use this technique in our framework at @jux: create a special Collection that contains all instantiated Models, so that if you try to create a new Model with the same 'id' as an existing one, it just gives back that same instance. Has saved a lot of headaches, but I know this isn't necessarily a common Backbone pattern.

caseywebdev commented 11 years ago

I've done this before too, but I'd like to avoid it if we can. Do you have a scenario in mind where we would need this?

afeld commented 11 years ago

I was going to try to convert the owner objects under each app.Issue to proper app.Users, where many issues could share the same owner. Maybe doing that nested model isn't necessary, but we might want to point out having duplicate models is something to watch out for.

caseywebdev commented 11 years ago

Well right now we can do

var issuesForLogin = app.board.issues.filter(function (issue) {
  return issue.get('user').login === 'afeld';
});

to get issues by submitter. If you want issues by owner

var issuesForOwner = app.board.issues.filter(function (issue) {
  return issue.repo.get('owner').login === 'afeld';
});

I think these help showcase the underscore collection methods also.

davidgtonge commented 11 years ago

I like the underscore filter approach.