i want to use this library react-native-storage in my cljs project, and write the code:
(def storage (new Storage #js {:size 1000
:storageBackend js/window.localStorage
:defaultExpires (* 1000 3600 24)
:enableCache true}))
(.save storage #js {:key :username :data "vinurs"})
(.load storage #js {:key :username})
this is the load function it provided:
// load
storage
.load({
key: 'loginState',
// autoSync (default: true) means if data is not found or has expired,
// then invoke the corresponding sync method
autoSync: true,
// syncInBackground (default: true) means if data expired,
// return the outdated data first while invoking the sync method.
// If syncInBackground is set to false, and there is expired data,
// it will wait for the new data and return only after the sync completed.
// (This, of course, is slower)
syncInBackground: true,
// you can pass extra params to the sync method
// see sync example below
syncParams: {
extraFetchOptions: {
// blahblah
},
someFlag: true
}
})
.then(ret => {
// found data go to then()
console.log(ret.userid);
})
.catch(err => {
// any exception including data not found
// goes to catch()
console.warn(err.message);
switch (err.name) {
case 'NotFoundError':
// TODO;
break;
case 'ExpiredError':
// TODO
break;
}
});
i don’t know how to convert it to cljs, and load the key’s value in cljs