Last active
August 29, 2015 14:21
-
-
Save mrzor/8d0d12be413e873682b8 to your computer and use it in GitHub Desktop.
PouchDB / Livereload fix
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
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