Browse Source

Refactoring

develop
Ezerous 4 years ago
parent
commit
31d4b5a601
  1. 29
      src/breezeStatus/breezeStatusReducer.js
  2. 4
      src/constants.js
  3. 5
      src/index.js
  4. 17
      src/ipfs/ipfsReducer.js
  5. 5
      src/orbit/orbitActions.js
  6. 2
      src/orbit/orbitConstants.js
  7. 23
      src/orbit/orbitReducer.js
  8. 2
      src/orbit/orbitUtils.js

29
src/breezeStatus/breezeStatusReducer.js

@ -1,20 +1,33 @@
import * as BreezeActions from './breezeActions'
import { STATUS_INITIALIZING, STATUS_INITIALIZED, STATUS_FAILED } from "../constants";
import { BREEZE_INITIALIZING,BREEZE_INITIALIZED, BREEZE_FAILED } from "./breezeActions";
const initialState = {
initialized: false
status: STATUS_INITIALIZING
}
const breezeStatusReducer = (state = initialState, action) => {
/*
* Breeze Status
*/
if (action.type === BreezeActions.BREEZE_INITIALIZED) {
return {
...state,
initialized: true
}
switch (action.type) {
case BREEZE_INITIALIZING:
return {
...state,
status: STATUS_INITIALIZING
};
case BREEZE_INITIALIZED:
return {
...state,
status: STATUS_INITIALIZED
};
case BREEZE_FAILED:
return {
...state,
status: STATUS_FAILED
};
default:
return state;
}
return state
}
export default breezeStatusReducer

4
src/constants.js

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

5
src/index.js

@ -9,7 +9,9 @@ import orbitSaga from "./orbit/orbitSaga";
import * as BreezeActions from './breezeStatus/breezeActions'
import * as OrbitActions from './orbit/orbitActions'
import * as orbitTypes from './orbit/constants'
import * as breezeConstants from './constants'
import * as orbitTypes from './orbit/orbitConstants'
import orbitMiddleware from "./orbit/orbitMiddleware";
import orbitStatusSaga from "./orbit/orbitStatusSaga";
@ -36,6 +38,7 @@ const breezeActions = {
export {
Breeze,
breezeConstants,
breezeActions,
breezeReducers,
breezeMiddlewares,

17
src/ipfs/ipfsReducer.js

@ -1,20 +1,29 @@
import {IPFS_FAILED, IPFS_INITIALIZED} from "./ipfsActions";
import { IPFS_INITIALIZING , IPFS_INITIALIZED, IPFS_FAILED } from "./ipfsActions";
import { STATUS_INITIALIZING, STATUS_INITIALIZED, STATUS_FAILED } from "../constants";
const initialState = {
initialized: false
status: STATUS_INITIALIZING
};
const ipfsReducer = (state = initialState, action) => {
/*
* IPFS Status
*/
switch (action.type) {
case IPFS_INITIALIZING:
return {
...state,
status: STATUS_INITIALIZING
};
case IPFS_INITIALIZED:
return {
...state,
initialized: true
status: STATUS_INITIALIZED
};
case IPFS_FAILED:
return {
...state,
failed: true
status: STATUS_FAILED
};
default:
return state;

5
src/orbit/orbitActions.js

@ -1,9 +1,14 @@
// OrbitDB Status
export const ORBIT_INITIALIZING = 'ORBIT_INITIALIZING';
export const ORBIT_INITIALIZED = 'ORBIT_INITIALIZED';
export const ORBIT_INIT_FAILED = 'ORBIT_INIT_FAILED';
// Identity Provider Status
export const ORBIT_IDENTITY_PROVIDER_ADD = 'ORBIT_IDENTITY_PROVIDER_ADD';
export const ORBIT_IDENTITY_PROVIDER_ADDED = 'ORBIT_IDENTITY_PROVIDER_ADDED';
export const ORBIT_IDENTITY_PROVIDER_FAILED = 'ORBIT_IDENTITY_PROVIDER_FAILED';
// Database Status
export const ORBIT_DATABASE_CREATING = 'ORBIT_DATABASE_CREATING';
export const ORBIT_DATABASE_CREATED = 'ORBIT_DATABASE_CREATED';
export const ORBIT_DATABASE_FAILED = 'ORBIT_DATABASE_FAILED';

2
src/orbit/constants.js → src/orbit/orbitConstants.js

@ -5,7 +5,7 @@ export const ORBIT_TYPE_KEYVALUE = 'keyvalue';
export const ORBIT_TYPE_DOCS = 'docs';
export const ORBIT_TYPE_COUNTER = 'counter';
// OrbitDB statuses
// OrbitDB Databases status
export const DB_STATUS_INIT = 'init';
export const DB_STATUS_READY = 'ready';
export const DB_STATUS_REPLICATING = 'replicating';

23
src/orbit/orbitReducer.js

@ -3,32 +3,41 @@ import {
ORBIT_DATABASE_READY,
ORBIT_DATABASE_REPLICATED,
ORBIT_DATABASE_REPLICATING,
ORBIT_INIT_FAILED,
ORBIT_INITIALIZED
ORBIT_INITIALIZING,
ORBIT_INITIALIZED,
ORBIT_INIT_FAILED
} from "./orbitActions";
import {
DB_STATUS_INIT,
DB_STATUS_READY,
DB_STATUS_REPLICATED,
DB_STATUS_REPLICATING
} from "./constants";
DB_STATUS_REPLICATING,
} from "./orbitConstants";
import {STATUS_INITIALIZING, STATUS_INITIALIZED, STATUS_FAILED } from "../constants";
const initialState = {
initialized: false,
status: STATUS_INITIALIZING,
databases: {}
};
const orbitReducer = (state = initialState, action) => {
switch (action.type) {
case ORBIT_INITIALIZING:
return {
...state,
status: STATUS_INITIALIZING
};
case ORBIT_INITIALIZED:
return {
...state,
initialized: true,
status: STATUS_INITIALIZED
};
case ORBIT_INIT_FAILED:
return {
...state,
failed: true,
status: STATUS_FAILED
};
case ORBIT_DATABASE_CREATED:
return newDatabasesStatus(state, action, DB_STATUS_INIT);

2
src/orbit/orbitUtils.js

@ -1,4 +1,4 @@
import * as orbitTypes from "./constants";
import * as orbitTypes from "./orbitConstants";
export function resolveOrbitDBTypeFun(orbitdb, type){
let dbTypeFun;

Loading…
Cancel
Save