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

Do not override Backbone.sync #75

Closed
rubennorte opened this issue Feb 21, 2014 · 7 comments
Closed

Do not override Backbone.sync #75

rubennorte opened this issue Feb 21, 2014 · 7 comments

Comments

@rubennorte
Copy link
Contributor

I think Backbone adapters shouldn't modify the original sync function since it can be a important source of incompatibilities with other libs. It could just provide the sync function to be used on the selected models and collections (or manually overriding the default function if we want to).

Here's an example of a better approach IMO:

var LocalModel = Backbone.Model.extend({
  sync: Backbone.localforage.sync,
  offlineStore: new Backbone.localforage.Store('name')
});

Any ideas?

@tofumatt
Copy link
Member

If it’s that simple that works for me. I don’t like the override we do but I haven’t ever built a big Backbone app with multiple sync adapters, so I’m a bit out of my depth on what the best practice is.

@rubennorte
Copy link
Contributor Author

I'm sure the current implementation works for most users, but with a little change it can work for everyone. It just occurred to me a simpler usage:

var LocalModel = Backbone.Model.extend({
  sync: Backbone.localforage.sync('storename') // Use a store for the model
});

var OtherLocalModel = Backbone.Model.extend({
  sync: Backbone.localforage.sync() // Use the model's collection store
});

I can send a pull request if there's consensus about this.

@tofumatt
Copy link
Member

Oh wow, I really like that. That would be amazing 👍

@magalhas
Copy link
Contributor

I like that as well.

@tofumatt
Copy link
Member

Fixed in ff38f31

@magalhas
Copy link
Contributor

I'll fix the Backbone example according to this changes.

@tofumatt
Copy link
Member

I already did, no worries :-)

Matthew Riley MacPherson (Sent from mobile)

On Feb 22, 2014, at 17:32, José Magalhães notifications@github.com wrote:

I'll fix the Backbone example according to this changes.


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants