modules: more browser compat.

This commit is contained in:
Christopher Jeffrey 2016-11-18 23:33:05 -08:00
parent 354cf00158
commit baffd161b8
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 10 additions and 25 deletions

View File

@ -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;

View File

@ -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.
*/

View File

@ -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",