Last active
December 11, 2015 00:59
-
-
Save calvinmetcalf/4520740 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
class PouchCore | |
constructor: (@remoteUrl,@onChange)-> | |
if @remoteUrl.slice(0,4)=="http" #did we get a real url? | |
parts = @remoteUrl.split("/") #split the url bu by the slashes | |
@_dbName = parts.pop() #assign the last part as the db name | |
while @_dbName == "" #unless it is an empty string | |
@_dbName = parts.pop()#repeat until you find one | |
Pouch @_dbName, (e, db) => #making the local db | |
unless e #error would imply we are on an old browser | |
@db = db | |
@db.changes( | |
continuous : true | |
include_docs : true | |
onChange : @onChange | |
) | |
#we replicate | |
@db.replicate.to @remoteUrl {continuous: true} | |
@db.replicate.from @remoteUrl {continuous: true} | |
@ | |
else #there was an error lets try again but just with the remote one | |
Pouch @remoteUrl, (e, db) => | |
unless e | |
@db | |
@db.changes( | |
continuous : true | |
include_docs : true | |
onChange : @onChange | |
) | |
@ | |
else | |
return "yeah something went wrong" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment