I don't want to override Backbone.sync()
as some of my models will actually use the standard sync()
.
Is it good practice to override fetch()
and save()
directly from the Model?
It is not necessary to override sync
globally. You can do it per Model/Collection ie,
var MyModel = Backbone.Model.extend({
sync: customSync,
...
});
This avoids overriding Backbone.sync globally.
Now if you do not need to implement a full sync, for instance it you only need to override fetch
, you can of course do so on a per model basis too.
Presumably you have seen Backbone.sync being overriden by the localStorage version. This is indeed not necessary (I would think it is bad practice). It is sufficient to just define the custom sync
function and let models/collections use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With