we need to cover some corner cases in model.js
and add some caching so that it's easier to do good MVC design.
@ralphsmith80 and i went over some ideas, and came up with some notes:
-
Collection.prototype.load
is cached by default, you can explicitly re-send the request with the{reload: true}
parameter -
Model.prototype.refresh
on the other hand re-sends the request by default, and you can get a cached result by explicitly settingconditional: true
- TODO: add
Model.prototype.load
that behaves like the collection method, essentially just calling refresh w/ the conditional flag set to true - TODO: when refresh is called and there is an in-flight request, just return the promise of the in-flight request
- TODO: handle out-of-order responses
- TODO: add
-
Model.prototype.save
sends a new request if and only if changes were made to the model- TODO: when save is called and there is an in-flight request:
- return the current request's promise if there haven't been any changes
- make a new request if changes were made since the first request went out
- TODO: handle out-of-order responses
- TODO: when save is called and there is an in-flight request:
-
Model.prototype.destroy
- TODO: if this is called when an existing request is in-flight, just return the current request's promise
- TODO: if this is called and a previous destroy request succeeded, return the previous promise
- TODO: handle
model.destroy().then(function() {m.save();})
i don't think there's actually anything that needs to be done to handle out-of-order responses to 'save' calls, since it resolves the deferred by just passing a copy of the model anyway.