src/decentralizer.js
// define an async method for initializing IPFS and OrbitDb
define an async method for initializing IPFS and OrbitDb
define an async method for initializing IPFS and OrbitDb
async initialize() {
    if (this.isInitialized) {
      return true;
    }
    try {
      if (this.config.ipfsOptions.apiUri) {
        this._ipfs = IpfsApi(this.config.ipfsOptions.apiUri);
      } else {
        this._ipfs = await IPFS.create(this.config.ipfsOptions);
      }
      this._orbitDb = await OrbitDb.createInstance(this._ipfs);
      this._logDb = await this._orbitDb.log(
        this.config.orbitdbOptions.LOG_DATABASE,
        { localOnly: false, sync: true },
      );
      console.log("OrbitDB synced with:", this._logDb.address.toString());
      await this._logDb.load();
      this.isInitialized = true;
      return true;
    } catch (err) {
      console.log(err);
      return err;
    }
  }
async initialize ( ) { if ( this . isInitialized ) { return true ; } try { if ( this . config . ipfsOptions . apiUri ) { this . _ipfs = IpfsApi ( this . config . ipfsOptions . apiUri ) ; } else { this . _ipfs = await IPFS . create ( this . config . ipfsOptions ) ; } this . _orbitDb = await OrbitDb . createInstance ( this . _ipfs ) ; this . _logDb = await this . _orbitDb . log ( this . config . orbitdbOptions . LOG_DATABASE , { localOnly : false , sync : true } , ) ; console . log ( "OrbitDB synced with:" , this . _logDb . address . toString ( ) ) ; await this . _logDb . load ( ) ; this . isInitialized = true ; return true ; } catch ( err ) { console . log ( err ) ; return err ; } }
define an async method for initializing IPFS and OrbitDb
define an async method for initializing IPFS and OrbitDb
// create the ipfs instance // create the orbitDb instance // define the specific logDb // load the logDb so we have it // resolve the initialize promise // if any of the above fails, reject the promise