Created
August 4, 2016 16:11
-
-
Save berry/493ba343f21f3b9d5e4ff3272c4b8000 to your computer and use it in GitHub Desktop.
orbit db
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
<script type="text/javascript"> | |
const address = 'localhost:3333'; | |
const username = 'user1'; | |
const password = ''; | |
const channel = 'test' | |
const ipfs = new window.Ipfs(); | |
const logger = Logger.create("orbit-db autorga", { color: Logger.Colors.Green, showTimestamp: true, showLevel: false }) | |
const orbit = OrbitDB.connect(address, username, password, ipfs); | |
const putget = (key,value) => { | |
orbit | |
.then((orbit) => orbit.kvstore(channel)) | |
.then((db) => { db.put(key, value) | |
.then((res) => { | |
const result = db.get(key) | |
print (result) | |
}) | |
}).catch((e) => logger.error(e)) | |
} | |
const put = (key,value) => { | |
orbit | |
.then((orbit) => orbit.kvstore(channel)) | |
.then((db) => { db.put(key, value) | |
.then((res) => print (res)) | |
}) | |
.catch((e) => logger.error(e)) | |
} | |
const get = (key) => { | |
orbit | |
.then((orbit) => orbit.kvstore(channel)) | |
.then((db) => { | |
const result = db.get(key) | |
print (result) | |
}).catch((e) => logger.error(e)) | |
} | |
const print = (res) => logger.log(res) | |
// 2016-08-04T15:52:45.933Z [DEBUG] orbit-db: Connecting to network localhost:3333 (localhost:3333) | |
// 2016-08-04T15:52:46.451Z [DEBUG] orbit-db: Connected to network localhost:3333 (localhost:3333) | |
// putget("a", "hellowaterworld") | |
// undefined | |
// 2016-08-04T15:53:10.270Z orbit-db autorga: hellowaterworld | |
// put("a", "hellowaterworld") | |
// undefined | |
// 2016-08-04T15:53:18.116Z orbit-db autorga: QmVGT4Lo8kbihYJ3S5ozXwZ2QvVJUnEiCK8H2TRvPgqNVW | |
// get("a") | |
// 2016-08-04T15:53:21.240Z orbit-db autorga: undefined | |
// undefined | |
</script> |
Thanks. That works! I hope the bug gets fixed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works if the code is changed to the following. Not sure why, will have to investigate. Likely a bug, so thanks for spotting!