Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* @flow */
import { Effects } from "redux-loop";
import type { Effect } from "redux-loop";
//
// Effects.none
//
// ok
const none: Effect = Effects.none();
//
// Effects.constant
//
// ok
const constant: Effect = Effects.constant({ type: "foo" });
// $ExpectError
Effects.constant({ noTypeProp: "foo" });
//
// Effects.call
//
function zeroArg() {
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) {
updateStopwatch: (state, { payload }) => {
const [stopwatch, actions] =
stopwatchModule.reducer(state.stopwatch, payload.action);
const newState = { ...state, stopwatch: stopwatch };
debugger;
return actions.length
? module.reducer(newState, actions[0])
: loop( newState, Effects.none() );
}
},