Browse Source

Refactoring

develop
Ezerous 4 years ago
parent
commit
410fefb21b
  1. 17
      src/Breeze.js
  2. 4
      src/breezeStatus/breezeStatusReducer.js
  3. 1
      src/constants.js
  4. 4
      src/index.js
  5. 4
      src/ipfs/ipfsReducer.js
  6. 2
      src/ipfs/ipfsSaga.js
  7. 4
      src/orbit/orbitReducer.js

17
src/Breeze.js

@ -2,6 +2,7 @@ import { BREEZE_INITIALIZING } from "./breezeStatus/breezeActions"
import defaultOptions from "./misc/defaultOptions"; import defaultOptions from "./misc/defaultOptions";
import merge from "./misc/mergeUtils" import merge from "./misc/mergeUtils"
import {addOrbitDB, removeOrbitDB, orbitInit} from "./orbit/orbitActions"; import {addOrbitDB, removeOrbitDB, orbitInit} from "./orbit/orbitActions";
import {STATUS_INITIALIZED} from "./constants";
// Load as promise so that async Breeze initialization can still resolve // Load as promise so that async Breeze initialization can still resolve
const isEnvReadyPromise = new Promise((resolve) => { const isEnvReadyPromise = new Promise((resolve) => {
@ -37,8 +38,20 @@ class Breeze {
}) })
} }
initOrbit(id) { async initOrbit(id) {
this.store.dispatch(orbitInit(this, id)); const { store, orbit } = this;
store.dispatch(orbitInit(this, id));
return new Promise(resolve => {
const unsubscribe = store.subscribe(() => {
const status = store.getState().orbit.status;
if (status === STATUS_INITIALIZED) {
unsubscribe();
return resolve(orbit);
}
})
});
} }
// dbInfo = {address, type} (where address can also be a name) // dbInfo = {address, type} (where address can also be a name)

4
src/breezeStatus/breezeStatusReducer.js

@ -1,8 +1,8 @@
import { STATUS_INITIALIZING, STATUS_INITIALIZED, STATUS_FAILED } from "../constants"; import { STATUS_UNINITIALIZED, STATUS_INITIALIZING, STATUS_INITIALIZED, STATUS_FAILED } from "../constants";
import { BREEZE_INITIALIZING,BREEZE_INITIALIZED, BREEZE_FAILED } from "./breezeActions"; import { BREEZE_INITIALIZING,BREEZE_INITIALIZED, BREEZE_FAILED } from "./breezeActions";
const initialState = { const initialState = {
status: STATUS_INITIALIZING status: STATUS_UNINITIALIZED
} }
const breezeStatusReducer = (state = initialState, action) => { const breezeStatusReducer = (state = initialState, action) => {

1
src/constants.js

@ -1,4 +1,5 @@
// Status // Status
export const STATUS_UNINITIALIZED = 'uninitialized';
export const STATUS_INITIALIZING = 'initializing'; export const STATUS_INITIALIZING = 'initializing';
export const STATUS_INITIALIZED = 'initialized'; export const STATUS_INITIALIZED = 'initialized';
export const STATUS_FAILED = 'failed'; export const STATUS_FAILED = 'failed';

4
src/index.js

@ -7,6 +7,7 @@ import breezeStatusSaga from './breezeStatus/breezeStatusSaga';
import orbitSaga from "./orbit/orbitSaga"; import orbitSaga from "./orbit/orbitSaga";
import * as BreezeActions from './breezeStatus/breezeActions' import * as BreezeActions from './breezeStatus/breezeActions'
import * as IpfsActions from './ipfs/ipfsActions'
import * as OrbitActions from './orbit/orbitActions' import * as OrbitActions from './orbit/orbitActions'
import * as breezeConstants from './constants' import * as breezeConstants from './constants'
@ -27,7 +28,8 @@ const breezeSagas = [
const breezeActions = { const breezeActions = {
breeze: BreezeActions, breeze: BreezeActions,
orbit: OrbitActions orbit: OrbitActions,
ipfs: IpfsActions
} }
export { export {

4
src/ipfs/ipfsReducer.js

@ -1,8 +1,8 @@
import { IPFS_INITIALIZING , IPFS_INITIALIZED, IPFS_FAILED } from "./ipfsActions"; import { IPFS_INITIALIZING , IPFS_INITIALIZED, IPFS_FAILED } from "./ipfsActions";
import { STATUS_INITIALIZING, STATUS_INITIALIZED, STATUS_FAILED } from "../constants"; import { STATUS_UNINITIALIZED, STATUS_INITIALIZING, STATUS_INITIALIZED, STATUS_FAILED } from "../constants";
const initialState = { const initialState = {
status: STATUS_INITIALIZING status: STATUS_UNINITIALIZED
}; };
const ipfsReducer = (state = initialState, action) => { const ipfsReducer = (state = initialState, action) => {

2
src/ipfs/ipfsSaga.js

@ -15,7 +15,7 @@ export function * initializeIPFS (ipfsOptions) {
// Initialize IPFS // Initialize IPFS
const ipfs = yield call(IPFS.create, ipfsOptions); const ipfs = yield call(IPFS.create, ipfsOptions);
yield put({ type: IpfsActions.IPFS_INITIALIZED }); yield put({ type: IpfsActions.IPFS_INITIALIZED, ipfs });
return ipfs; return ipfs;
} catch (error) { } catch (error) {

4
src/orbit/orbitReducer.js

@ -19,10 +19,10 @@ import {
DB_STATUS_REMOVED DB_STATUS_REMOVED
} from "./orbitConstants"; } from "./orbitConstants";
import {STATUS_INITIALIZING, STATUS_INITIALIZED, STATUS_FAILED } from "../constants"; import { STATUS_UNINITIALIZED, STATUS_INITIALIZING, STATUS_INITIALIZED, STATUS_FAILED } from "../constants";
const initialState = { const initialState = {
status: STATUS_INITIALIZING, status: STATUS_UNINITIALIZED,
databases: {} databases: {}
}; };

Loading…
Cancel
Save