Skip to content

Instantly share code, notes, and snippets.

@mrzor
Last active August 29, 2015 14:21
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 mrzor/8d0d12be413e873682b8 to your computer and use it in GitHub Desktop.
Save mrzor/8d0d12be413e873682b8 to your computer and use it in GitHub Desktop.
PouchDB / Livereload fix
window.Database = new PouchDB("mybrowserdb");
window.RemoteDatabase = new PouchDB(remoteUri);
window.RemoteSync = PouchDB.sync(Database, RemoteDatabase,
live: true
).on 'paused', (info) ->
console.info "replication paused (are we offline?)", info
.on 'active', () ->
console.info "replication active (are we back online?)"
.on 'denied', (err) ->
console.error "replication denied", err
.on 'error', (err) ->
console.error "replication error", err
# This would explode
window.location.reload
# Kill replication on page unload (for livereload-triggered excepton)
window.addEventListener "beforeunload", (event) ->
window.RemoteSync.cancel()
# This would not.
window.location.reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment