Last active
April 16, 2024 07:30
-
-
Save dominictarr/4366290 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
function create (path) | |
var db = require('levelup')(path, {createIfMissing: true}) | |
var Replicator = require('level-replicator') | |
var replicator = Replicator(db, { | |
prefix:'replicateable', | |
merge: function (oldVal, newVal) { | |
if(!oldVal) return newVal | |
//handle the differences between old and new, | |
//the user is expected to implement some version system, | |
//and store that data in the object... | |
//vector clocks, or couchdb style hash pointers are good options. | |
if(illegalUpdate(oldVal, newVal)) throw new Error('invalid') | |
return merge(oldVal, newVal) | |
} | |
}) | |
return replicator | |
} | |
var a = create('/tmp/A') | |
var b = create('/tmp/B') | |
var as = a.createStream() | |
as.pipe(b.createStream()).pipe(as) | |
a.put(key, value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Many open-source developers have been posting requests for assistance with project automation and functional testing for uno online.