From 99cb0e92dfb11c16288873d06169c68536985f9c Mon Sep 17 00:00:00 2001 From: Hadar Rottenberg Date: Thu, 21 May 2020 22:10:07 +0300 Subject: [PATCH] add: lates ras.js --- lib/ras.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/ras.js b/lib/ras.js index d1553a78..c0c955a7 100644 --- a/lib/ras.js +++ b/lib/ras.js @@ -1,40 +1,41 @@ -;(function(){ +(function(){ /** Radix AsyncStorage adapter make sure to pass AsyncStorage instance in opt.AsyncStorage + example: + import AsyncStorage from 'react-native' + const store = Store({AsyncStorage}) + const gun = new Gun({store,peers:[...]}) **/ function Store(opt){ opt = opt || {}; - const store = () => { - const as = opt.AsyncStorage; - const put = (key, data, cb) => + const store = function(){} + const as = opt.AsyncStorage; + store.put = function(key, data, cb) { as.setItem(''+key,data) .then(_ => cb(null,1)) + .then(_ => console.log("ok put")) .catch(_ => { console.error(`failed saving to asyncstorage`,{key, data}) cb(null,0) }) } - const get = (key,cb) => { + store.get = (key,cb) => { as.getItem(''+key) .then(data => cb(null,data)) + .then(_ => console.log("ok get")) .catch(_ => { console.error(`failed fetching from asyncstorage`,{key}) cb(null,0) }) } - } return store; } - if(typeof window !== "undefined"){ - (Store.window = window).RasyncStorage = Store; - } else { - try{ module.exports = Store }catch(e){} - } + module.exports = Store }()); \ No newline at end of file