Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function nestedAction(time: Date, action: { type: $Subtype }) {
return { type: "NESTED_ACTION", payload: action, time };
}
function nestedActionWrongArgOrder(
action: { type: $Subtype },
time: Date
) {
return { type: "NESTED_ACTION", payload: action, time };
}
const nestedEffect = Effects.call(zeroArg);
// ok
Effects.lift(nestedEffect, nestedAction, new Date());
// $ExpectError
Effects.lift(nestedEffect, nestedActionWrongArgOrder, new Date());
function toReduxLoopEffect(effect) { // eslint-disable-line consistent-return
switch (effect.type) { // eslint-disable-line default-case
case 'NONE': return Effects.none();
case 'PROMISE': {
const factory = () => { // eslint-disable-line arrow-body-style
return effect.factory()
.then(result => effect.successTagger(result), error => effect.failTagger(error));
};
return Effects.promise(factory);
}
case 'MAP': {
return Effects.lift(toReduxLoopEffect(effect.effect), effect.tagger);
}
case 'BATCH': {
return Effects.batch(effect.effects.map(batchedEffect => toReduxLoopEffect(batchedEffect)));
}
}
}
function toReduxLoopEffect(effect) {
switch(effect.type) {
case 'NONE': return Effects.none();
case 'PROMISE': {
const factory = () => {
return effect.factory()
.then(result => effect.successTagger(result), error => effect.failTagger(error))
};
return Effects.promise(factory);
};
case 'MAP': {
return Effects.lift(toReduxLoopEffect(effect.effect), effect.tagger);
};
case 'BATCH': {
return Effects.batch(effect.effects.map(batchedEffect => toReduxLoopEffect(batchedEffect)));
};
}
}
function toReduxLoop(reduction) {
updateChild: ({ children, ...state }, { payload, meta }) => {
const childToUpdate = children[meta.id];
const [updatedChild, neff] = module.reducer(childToUpdate, payload);
const effects =
Effects.lift(neff, a => module.actions.updateChild(a, { id: meta.id }));
return loop(
{ ...state, children: { ...children, [meta.id]: updatedChild } },
effects,
);
},
},
childrenEff.map((effect, id) =>
Effects.lift(effect, a => module.actions.updateChild(a, { id })),
),
updateContent: (state, { payload: action }) => {
const [content, effect] = childModules[state.contentType].reducer(
state.content,
action,
);
return loop(
{ ...state, content },
Effects.lift(effect, a => module.actions.updateContent(a)),
);
},
split: (state, { payload: orientation }) => {