diff --git a/lib/env.js b/lib/env.js index c7ab35a4..f86cd5ea 100644 --- a/lib/env.js +++ b/lib/env.js @@ -7,6 +7,8 @@ 'use strict'; +var lazy = require('./utils/lazy'); + /** * A BCoin "environment" which is used for * bootstrapping the initial `bcoin` module. @@ -105,6 +107,7 @@ function Environment() { this.env = Environment; + this.require = lazy(require, this); // BN this.require('bn', 'bn.js'); @@ -208,21 +211,6 @@ function Environment() { this.require('bip70', './bip70'); } -/** - * Assign a lazily required module. - * @param {String} key - * @param {String} path - */ - -Environment.prototype.require = function _require(key, path) { - var cache; - this.__defineGetter__(key, function() { - if (!cache) - cache = require(path); - return cache; - }); -}; - /** * Set the default network. * @param {String} options @@ -260,12 +248,12 @@ Environment.prototype.now = function now() { */ Environment.prototype.cache = function cache() { - require('./node/fullnode'); - require('./node/spvnode'); - require('./http'); - require('./crypto/schnorr'); - require('./utils/uri'); - require('./bip70'); + this.fullnode; + this.spvnode; + this.http; + this.crypto.schnorr; + this.uri; + this.bip70; }; /* @@ -273,7 +261,6 @@ Environment.prototype.cache = function cache() { * Environment. */ -exports.require = Environment.prototype.require; exports.cache = Environment.prototype.cache; exports.set = Environment.prototype.set; exports.now = Environment.prototype.now; diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 74cc8540..61a77a33 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -1946,9 +1946,6 @@ utils.U32 = function U32(num) { utils.lazy = require('./lazy'); -if (utils.lazy.unsupported) - utils.lazy = function() { return utils.nop; }; - /* * Expose other objects. */ diff --git a/package.json b/package.json index b2da1eaa..0ee0f70a 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "./lib/utils/native": "./browser/empty.js", "./lib/utils/nfkd": "./lib/utils/nfkd-browser.js", "./lib/utils/nexttick": "./lib/utils/nexttick-browser.js", + "./lib/utils/lazy": "./lib/utils/lazy-browser.js", "./lib/crypto/backend": "./lib/crypto/backend-browser.js", "./lib/crypto/ec": "./lib/crypto/ec-elliptic.js", "./lib/crypto/pk": "./lib/crypto/pk-browser.js",