Ryan X. Charles
11 years ago
3 changed files with 40 additions and 40 deletions
@ -1,49 +1,50 @@ |
|||||
/* |
/* |
||||
* Bitcore bindings for the browser |
One way to require files is this simple way: |
||||
*/ |
module.exports.Address = require('./Address'); |
||||
|
|
||||
|
|
||||
|
|
||||
module.exports.bignum = require('bignum'); |
|
||||
module.exports.base58 = require('base58-native'); |
|
||||
module.exports.buffertools = require('buffertools'); |
|
||||
|
|
||||
module.exports.config = require('./config'); |
However, that will load all classes in memory even if they are not used. |
||||
module.exports.const = require('./const'); |
Instead, we can set the 'get' property of each class to only require them when |
||||
module.exports.Deserialize = require('./Deserialize'); |
they are accessed, saving memory if they are not used in a given project. |
||||
module.exports.log = require('./util/log'); |
*/ |
||||
module.exports.networks = require('./networks'); |
var requireWhenAccessed = function(name, file) { |
||||
module.exports.util = require('./util/util'); |
Object.defineProperty(module.exports, name, {get: function() {return require(file)}}); |
||||
|
}; |
||||
|
|
||||
module.exports.EncodedData = require('./util/EncodedData'); |
requireWhenAccessed('bignum', 'bignum'); |
||||
module.exports.VersionedData = require('./util/VersionedData'); |
requireWhenAccessed('base58', 'base58-native'); |
||||
module.exports.Address = require('./Address'); |
requireWhenAccessed('buffertools', 'buffertools'); |
||||
module.exports.Opcode = require('./Opcode'); |
requireWhenAccessed('config', './config'); |
||||
module.exports.Script = require('./Script'); |
requireWhenAccessed('const', './const'); |
||||
module.exports.Transaction = require('./Transaction'); |
requireWhenAccessed('Deserialize', './Deserialize'); |
||||
module.exports.Connection = require('./Connection'); |
requireWhenAccessed('log', './util/log'); |
||||
module.exports.Peer = require('./Peer'); |
requireWhenAccessed('networks', './networks'); |
||||
module.exports.Block = require('./Block'); |
requireWhenAccessed('util', './util/util'); |
||||
module.exports.ScriptInterpreter = require('./ScriptInterpreter'); |
requireWhenAccessed('EncodedData', './util/EncodedData'); |
||||
module.exports.Bloom = require('./Bloom'); |
requireWhenAccessed('VersionedData', './util/VersionedData'); |
||||
module.exports.KeyModule = require('./Key'); |
requireWhenAccessed('Address', './Address'); |
||||
module.exports.SINKey = require('./SINKey'); |
requireWhenAccessed('Opcode', './Opcode'); |
||||
module.exports.SIN = require('./SIN'); |
requireWhenAccessed('Script', './Script'); |
||||
module.exports.PrivateKey = require('./PrivateKey'); |
requireWhenAccessed('Transaction', './Transaction'); |
||||
module.exports.RpcClient = require('./RpcClient'); |
requireWhenAccessed('Connection', './Connection'); |
||||
module.exports.Wallet = require('./Wallet'); |
requireWhenAccessed('Peer', './Peer'); |
||||
module.exports.WalletKey = require('./WalletKey'); |
requireWhenAccessed('Block', './Block'); |
||||
|
requireWhenAccessed('ScriptInterpreter', './ScriptInterpreter'); |
||||
|
requireWhenAccessed('Bloom', './Bloom'); |
||||
|
requireWhenAccessed('KeyModule', './Key'); |
||||
|
requireWhenAccessed('SINKey', './SINKey'); |
||||
|
requireWhenAccessed('SIN', './SIN'); |
||||
|
requireWhenAccessed('PrivateKey', './PrivateKey'); |
||||
|
requireWhenAccessed('RpcClient', './RpcClient'); |
||||
|
requireWhenAccessed('Wallet', './Wallet'); |
||||
|
requireWhenAccessed('WalletKey', './WalletKey'); |
||||
module.exports.Buffer = Buffer; |
module.exports.Buffer = Buffer; |
||||
|
|
||||
if (typeof process.versions === 'undefined') { |
if (typeof process.versions === 'undefined') { |
||||
// Browser specific
|
// Browser specific
|
||||
module.exports.bignum.config({EXPONENTIAL_AT: 9999999, DECIMAL_PLACES: 0, ROUNDING_MODE: 1}); |
module.exports.bignum.config({EXPONENTIAL_AT: 9999999, DECIMAL_PLACES: 0, ROUNDING_MODE: 1}); |
||||
// module.exports.PeerManager = function () {
|
|
||||
// throw new Error('PeerManager not availabe in browser Bitcore, under .bitcore. Use it with: require(\'PeerManager\');');
|
|
||||
// };
|
|
||||
} |
} |
||||
else { |
else { |
||||
// Nodejs specific
|
// Nodejs specific
|
||||
module.exports.PeerManager = require('./PeerManager'); |
requireWhenAccessed('PeerManager', './PeerManager'); |
||||
} |
} |
||||
|
|
||||
|
Loading…
Reference in new issue