pixie-transformer
Version:
Pixie Transformer is transforming a Raw/Response JSON Payload into your expected JSON Payload. It's make your life easy and convenience without any logic required in your code.
34 lines (33 loc) • 852 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConditionReducer = (state, action) => {
if (typeof state === 'undefined') {
return {};
}
let parent = action.parent;
let child = action.child;
let data = action.data;
if (action.type) {
if (state.hasOwnProperty(parent)) {
if (state[parent].hasOwnProperty(child)) {
state[parent][child].push(data);
}
else {
state[parent][child] = [data];
}
}
else {
state[parent] = {};
state[parent][child] = [data];
}
}
else {
if (state.hasOwnProperty(parent)) {
state[parent].push(data);
}
else {
state[parent] = [data];
}
}
return state;
};