Skip to content

Instantly share code, notes, and snippets.

@aaronj1335
Last active December 10, 2015 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronj1335/4494686 to your computer and use it in GitHub Desktop.
Save aaronj1335/4494686 to your computer and use it in GitHub Desktop.
model.js todo

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 setting conditional: 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
  • 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
  • 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();})
@aaronj1335
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment