Skip to content

Instantly share code, notes, and snippets.

@designeng
Forked from benschwarz/sync-localStorage.coffee
Created September 6, 2013 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save designeng/6468476 to your computer and use it in GitHub Desktop.
Save designeng/6468476 to your computer and use it in GitHub Desktop.
sync: ( method, collection, options ) ->
content = localStorage.getItem( @url() ) if localStorage
if content and not navigator.onLine
options.success JSON.parse content
else
return Backbone.sync( method, collection, options ).done ( response ) =>
localStorage.setItem( @url(), JSON.stringify( response ) ) if localStorage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment