Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global model cache? #14

Closed
afeld opened this issue Jan 24, 2013 · 4 comments
Closed

Global model cache? #14

afeld opened this issue Jan 24, 2013 · 4 comments
Labels

Comments

@afeld
Copy link
Contributor

afeld commented Jan 24, 2013

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
Copy link
Contributor

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
Copy link
Contributor Author

afeld commented Jan 24, 2013

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
Copy link
Contributor

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
Copy link
Collaborator

I like the underscore filter approach.

@afeld afeld closed this as completed Jan 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants