raiden-ts
Version:
Raiden Light Client Typescript/Javascript SDK
54 lines • 2.5 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.raidenReducer = void 0;
const unset_1 = __importDefault(require("lodash/fp/unset"));
const actions_1 = require("./actions");
const reducer_1 = __importDefault(require("./channels/reducer"));
const reducer_2 = __importDefault(require("./services/reducer"));
const state_1 = require("./state");
const reducer_3 = __importDefault(require("./transfers/reducer"));
const reducer_4 = __importDefault(require("./transport/reducer"));
const actions_2 = require("./utils/actions");
// update state.config on raidenConfigUpdate action
// resets key to default value if value is undefined, otherwise overwrites it
const configReducer = (0, actions_2.createReducer)(state_1.initialState)
.handle(actions_1.raidenConfigUpdate, (state, { payload }) => {
let config = state.config;
for (const [k, v] of Object.entries(payload)) {
if (v !== undefined)
config = { ...config, [k]: v };
else if (k in config)
config = (0, unset_1.default)(k, config);
}
if (config === state.config)
return state;
return { ...state, config };
})
// raidenStarted changes reference to ensure state$ emits when starting
.handle(actions_1.raidenStarted, (state) => ({ ...state }));
const raidenReducers = {
configReducer,
channelsReducer: reducer_1.default,
transportReducer: reducer_4.default,
transfersReducer: reducer_3.default,
servicesReducer: reducer_2.default,
};
/**
* Raiden root reducer
* Apply action over each submodule root reducer in a flattened manner (iteratively).
* Notice the submodules reducers aren't handled only a partial/deep property of the state
* (as combineReducers), but instead receive the whole state, so they can act on any part of the
* state. This approach is similar to `reduce-reducers` util.
* Each submodule root reducer may then choose to split its concerns into nested or flattened
* reducers (like this one).
*
* @param state - Current RaidenState to reduce
* @param action - RaidenAction to apply over state
* @returns New RaidenState
*/
const raidenReducer = (state = state_1.initialState, action) => Object.values(raidenReducers).reduce((s, reducer) => reducer(s, action), state);
exports.raidenReducer = raidenReducer;
//# sourceMappingURL=reducer.js.map