@state-sync/redux-path-reducer
Version:
state-sync client only json path reducer
47 lines (46 loc) • 1.63 kB
JavaScript
;
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
function connectionStatusReducer(state, action) {
if (state === void 0) { state = { status: 'initialized' }; }
switch (action.type) {
case '@STATE_SYNC/CONNECTION_STATUS':
return action.payload;
case '@STATE_SYNC/CONNECTION_STATUS_TICK':
return state.status === 'disconnected' ?
{ status: 'disconnected', reconnectTimeout: state.reconnectTimeout ? state.reconnectTimeout - 1000 : 0 }
: state;
default:
return state;
}
}
function areasStatusReducer(state, action) {
if (state === void 0) { state = {}; }
switch (action.type) {
case '@STATE_SYNC/SYNC_AREA_STATUS':
var st = { id: action.area, status: action.status, ready: action.ready };
var tmp = __assign({}, state);
tmp[action.area] = st;
return tmp;
default:
return state;
}
}
function StateSyncStatusReducer(state, action) {
if (state === void 0) { state = {
connection: { status: 'initialized' },
areas: {}
}; }
return {
connection: connectionStatusReducer(state.connection, action),
areas: areasStatusReducer(state.areas, action)
};
}
exports.default = StateSyncStatusReducer;