mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
28 lines
675 B
JavaScript
28 lines
675 B
JavaScript
;(function(){
|
|
var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
|
|
|
|
Gun.on('create', function(root){
|
|
this.to.next(root);
|
|
root.opt.store = root.opt.store || Store(root.opt);
|
|
});
|
|
|
|
function Store(opt){
|
|
opt = opt || {};
|
|
opt.file = String(opt.file || 'radata');
|
|
if(Gun.TESTING){ opt.file = 'radatatest' }
|
|
var ls = localStorage;
|
|
|
|
var store = function Store(){};
|
|
|
|
store.put = function(key, data, cb){ ls[''+key] = data; cb(null, 1) }
|
|
store.get = function(key, cb){ cb(null, ls[''+key]) }
|
|
|
|
return store;
|
|
}
|
|
|
|
if(Gun.window){
|
|
Gun.window.RlocalStorage = Store;
|
|
} else {
|
|
module.exports = Store;
|
|
}
|
|
}()); |