diff --git a/lib/radisk.js b/lib/radisk.js index cdb8e2d25..fd83fddbf 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -590,17 +590,15 @@ } }()); - if(typeof window !== "undefined"){ - var Gun = window.Gun; - var Radix = window.Radix; - window.Radisk = Radisk; - } else { - var Gun = require('../gun'); - var Radix = require('./radix'); - //var Radix = require('./radix2'); Radisk = require('./radisk2'); - try{ module.exports = Radisk }catch(e){} - } + var Gun = (typeof window !== "undefined" && window.Gun)? window.Gun : require('../gun'); + var Radix = (typeof window !== "undefined" && window.Radix)? window.Radix : require('./radix'); Radisk.Radix = Radix; + ((name, exports) => { + try { module.exports = exports } catch (e) { } + if (typeof window !== "undefined") { + window[name] = window[name]||exports; + } + })("Radisk", Radisk); }()); \ No newline at end of file diff --git a/lib/radix.js b/lib/radix.js index e60789e4a..31bf0b7a2 100644 --- a/lib/radix.js +++ b/lib/radix.js @@ -108,11 +108,12 @@ } catch (e) { console.error(e); } }; - if(typeof window !== "undefined"){ - window.Radix = Radix; - } else { - try{ module.exports = Radix }catch(e){} - } + (function(name, exports){ + if(typeof window !== "undefined"){ + window[name] = window[name]||exports; + } + try{ module.exports = exports }catch(e){} + })("Radix",Radix); var each = Radix.object = function(o, f, r){ for(var k in o){ if(!o.hasOwnProperty(k)){ continue } diff --git a/lib/rfs.js b/lib/rfs.js index 7ab326971..c43b14f80 100644 --- a/lib/rfs.js +++ b/lib/rfs.js @@ -78,12 +78,12 @@ function Store(opt){ return store; } -var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); +var Gun = (typeof window !== "undefined" && window.Gun) ? window.Gun : require('../gun'); Gun.on('create', function(root){ this.to.next(root); var opt = root.opt; if(opt.rfs === false){ return } - opt.store = opt.store || (!Gun.window && Store(opt)); + opt.store = opt.store || (!Gun.window || opt.rfs === true && Store(opt)); }); module.exports = Store; \ No newline at end of file