rls.js 681 B

1234567891011121314151617181920212223242526272829
  1. ;(function(){
  2. function Store(opt){
  3. opt = opt || {};
  4. opt.file = String(opt.file || 'radata');
  5. var store = function Store(){};
  6. var ls = localStorage;
  7. store.put = function(key, data, cb){ ls[''+key] = data; cb(null, 1) }
  8. store.get = function(key, cb){ cb(null, ls[''+key]) }
  9. return store;
  10. }
  11. if(typeof window !== "undefined"){
  12. (Store.window = window).RlocalStorage = Store;
  13. } else {
  14. try{ module.exports = Store }catch(e){}
  15. }
  16. try{
  17. var Gun = Store.window.Gun || require('../gun');
  18. Gun.on('create', function(root){
  19. this.to.next(root);
  20. root.opt.store = root.opt.store || Store(root.opt);
  21. });
  22. }catch(e){}
  23. }());