UNPKG

core-native

Version:

A lightweight framework based on React Native + Redux + Redux Saga, in strict TypeScript.

53 lines 1.83 kB
import { __assign } from "tslib"; import { combineReducers } from "redux"; // Redux Action var SET_STATE_ACTION = "@@framework/setState"; // state must be complete module state, not partial export function setStateAction(module, state, type) { return { type: type, name: SET_STATE_ACTION, payload: { module: module, state: state }, }; } function setStateReducer(state, action) { var _a; if (state === void 0) { state = {}; } // Use action.name for set state action, make type specifiable to make tracking/tooling easier if (action.name === SET_STATE_ACTION) { var _b = action.payload, module_1 = _b.module, moduleState = _b.state; return __assign(__assign({}, state), (_a = {}, _a[module_1] = moduleState, _a)); } return state; } export var LOADING_ACTION = "@@framework/loading"; export function loadingAction(show, identifier) { if (identifier === void 0) { identifier = "global"; } return { type: LOADING_ACTION, payload: { identifier: identifier, show: show }, }; } function loadingReducer(state, action) { var _a; if (state === void 0) { state = {}; } if (action.type === LOADING_ACTION) { var payload = action.payload; var count = state[payload.identifier] || 0; return __assign(__assign({}, state), (_a = {}, _a[payload.identifier] = count + (payload.show ? 1 : -1), _a)); } return state; } // Root Reducer export function rootReducer() { return combineReducers({ loading: loadingReducer, app: setStateReducer, }); } // Helper function, to determine if show loading export function showLoading(state, identifier) { if (identifier === void 0) { identifier = "global"; } return state.loading[identifier] > 0; } //# sourceMappingURL=reducer.js.map