Forked from benschwarz/sync-localStorage.coffee
Last active
December 10, 2015 20:48
-
-
Save juliocesar/4490507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sync: ( method, collection, options ) -> | |
return Backbone.sync(method, collection, options) unless 'localStorage' in window | |
content = localStorage.getItem( @url() ) | |
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 ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment