Skip to content

Commit

Permalink
depenency upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
bdwain committed Jun 22, 2020
1 parent df8f6d8 commit 1f704fc
Show file tree
Hide file tree
Showing 19 changed files with 2,788 additions and 2,448 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"@typescript-eslint/eslint-plugin": "^3.2.0",
"@typescript-eslint/parser": "^3.2.0",
"babel-eslint": "^10.0.1",
"cross-env": "^5.0.5",
"eslint": "^6.1.0",
"cross-env": "^7.0.2",
"eslint": "^7.3.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-prettier": "^3.0.1",
"gitbook-cli": "^2.3.2",
Expand All @@ -79,15 +79,15 @@
"gitbook-plugin-github": "^3.0.0",
"gitbook-plugin-prism": "^2.3.0",
"immutable": "^3.7.6",
"jest": "^24.7.1",
"prettier": "1.18.2",
"jest": "^26.0.1",
"prettier": "2.0.5",
"redux": "^4.0.0",
"rimraf": "^3.0.0",
"rollup": "^1.10.1",
"rollup": "^2.18.0",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-terser": "^5.1.1",
"rollup-plugin-terser": "^6.1.0",
"typescript": "^3.2.2",
"typescript-definition-tester": "^0.0.6"
},
Expand Down
7 changes: 3 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import nodeResolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import replace from 'rollup-plugin-replace';
import { terser } from "rollup-plugin-terser";
import { terser } from 'rollup-plugin-terser';

var env = process.env.NODE_ENV;
var config = {
const env = process.env.NODE_ENV;
const config = {
output: {
format: 'umd',
name: 'ReduxLoop'
Expand All @@ -21,7 +21,6 @@ var config = {
};

if (env === 'production') {

config.plugins.push(terser());
}

Expand Down
60 changes: 30 additions & 30 deletions src/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const cmdTypes = {
SET_INTERVAL: 'SET_INTERVAL',
LIST: 'LIST',
MAP: 'MAP',
NONE: 'NONE'
NONE: 'NONE',
};

export function isCmd(object) {
return object ? !!object[isCmdSymbol] : false;
}

function getMappedCmdArgs(args = [], dispatch, getState) {
return args.map(arg => {
return args.map((arg) => {
if (arg === dispatchSymbol) {
return dispatch;
} else if (arg === getStateSymbol) {
Expand All @@ -36,7 +36,7 @@ function handleRunCmd(cmd, context) {

let onFail;
if (cmd.failActionCreator) {
onFail = error => {
onFail = (error) => {
if (!loopConfig.DONT_LOG_ERRORS_ON_HANDLED_FAILURES) {
console.error(error);
}
Expand All @@ -54,7 +54,7 @@ function handleRunCmd(cmd, context) {
);

if (isPromiseLike(result) && !cmd.forceSync) {
return result.then(onSuccess, onFail).then(action => {
return result.then(onSuccess, onFail).then((action) => {
return action ? [action] : [];
});
}
Expand All @@ -72,25 +72,25 @@ function handleRunCmd(cmd, context) {

function handleParallelList({ cmds, batch = false }, context) {
const promises = cmds
.map(nestedCmd => {
.map((nestedCmd) => {
const possiblePromise = executeCmdInternal(nestedCmd, context);
if (!possiblePromise || batch) {
return possiblePromise;
}

return possiblePromise.then(result => {
return Promise.all(result.map(a => context.wrappedDispatch(a)));
return possiblePromise.then((result) => {
return Promise.all(result.map((a) => context.wrappedDispatch(a)));
});
})
.filter(x => x);
.filter((x) => x);

if (promises.length === 0) {
return null;
}

return Promise.all(promises)
.then(flatten)
.then(actions => {
.then((actions) => {
return batch ? actions : [];
});
}
Expand All @@ -101,26 +101,26 @@ function handleSequenceList({ cmds, batch = false }, context) {
return null;
}

const result = new Promise(resolve => {
const result = new Promise((resolve) => {
let firstPromise = executeCmdInternal(firstCmd, context);
firstPromise = firstPromise || Promise.resolve([]);
firstPromise.then(result => {
firstPromise.then((result) => {
let executePromise;
if (!batch) {
executePromise = Promise.all(
result.map(a => context.wrappedDispatch(a))
result.map((a) => context.wrappedDispatch(a))
);
} else {
executePromise = Promise.resolve();
}
executePromise.then(() => {
const remainingSequence = list(cmds.slice(1), {
batch,
sequence: true
sequence: true,
});
const remainingPromise = executeCmdInternal(remainingSequence, context);
if (remainingPromise) {
remainingPromise.then(innerResult => {
remainingPromise.then((innerResult) => {
resolve(result.concat(innerResult));
});
} else {
Expand All @@ -137,8 +137,8 @@ function handleDelayCmd(cmd, context) {
const executeNestedCmd = () => {
const cmdPromise = executeCmdInternal(cmd.nestedCmd, context);
if (cmdPromise) {
cmdPromise.then(actions => {
actions.forEach(action => context.wrappedDispatch(action));
cmdPromise.then((actions) => {
actions.forEach((action) => context.wrappedDispatch(action));
});
}
};
Expand All @@ -162,7 +162,7 @@ export function executeCmd(cmd, dispatch, getState, loopConfig = {}) {
dispatch,
wrappedDispatch: dispatch,
getState,
loopConfig
loopConfig,
});
}

Expand All @@ -186,14 +186,14 @@ function executeCmdInternal(cmd, context) {
case cmdTypes.MAP: {
const possiblePromise = executeCmdInternal(cmd.nestedCmd, {
...context,
wrappedDispatch: action =>
context.wrappedDispatch(cmd.tagger(...cmd.args, action))
wrappedDispatch: (action) =>
context.wrappedDispatch(cmd.tagger(...cmd.args, action)),
});
if (!possiblePromise) {
return null;
}
return possiblePromise.then(actions =>
actions.map(action => cmd.tagger(...cmd.args, action))
return possiblePromise.then((actions) =>
actions.map((action) => cmd.tagger(...cmd.args, action))
);
}

Expand Down Expand Up @@ -257,7 +257,7 @@ function run(func, options = {}) {
type: cmdTypes.RUN,
func,
simulate: simulateRun,
...rest
...rest,
});
}

Expand All @@ -279,7 +279,7 @@ function action(actionToDispatch) {
[isCmdSymbol]: true,
type: cmdTypes.ACTION,
actionToDispatch,
simulate: simulateAction
simulate: simulateAction,
});
}

Expand Down Expand Up @@ -338,7 +338,7 @@ function delay(nestedCmd, delayMs, options, cmdType, funcName) {
nestedCmd,
delayMs,
scheduledActionCreator: options.scheduledActionCreator,
simulate: simulateDelay
simulate: simulateDelay,
});
}

Expand All @@ -360,7 +360,7 @@ function simulateDelay(timerId, nestedSimulation) {

function simulateList(simulations) {
return flatten(
this.cmds.map((cmd, i) => cmd.simulate(simulations[i])).filter(a => a)
this.cmds.map((cmd, i) => cmd.simulate(simulations[i])).filter((a) => a)
);
}

Expand Down Expand Up @@ -390,14 +390,14 @@ function list(cmds, options = {}) {
type: cmdTypes.LIST,
cmds,
simulate: simulateList,
...rest
...rest,
});
}

function simulateMap(simulation) {
let result = this.nestedCmd.simulate(simulation);
if (Array.isArray(result)) {
return result.map(action => this.tagger(...this.args, action));
return result.map((action) => this.tagger(...this.args, action));
} else if (result) {
return this.tagger(...this.args, result);
} else {
Expand All @@ -424,14 +424,14 @@ function map(nestedCmd, tagger, ...args) {
tagger,
nestedCmd,
args,
simulate: simulateMap
simulate: simulateMap,
});
}

const none = Object.freeze({
[isCmdSymbol]: true,
type: cmdTypes.NONE,
simulate: () => null
simulate: () => null,
});

export default {
Expand All @@ -445,5 +445,5 @@ export default {
map,
none,
dispatch: dispatchSymbol,
getState: getStateSymbol
getState: getStateSymbol,
};
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { install } from './install';

import c from './combine-reducers';
import m, {
DEPRECATED_mergeChildReducers as mergeChildReducersWithNoWarning
DEPRECATED_mergeChildReducers as mergeChildReducersWithNoWarning,
} from './merge-child-reducers';
import r from './reduce-reducers';

Expand Down
16 changes: 8 additions & 8 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { loopPromiseCaughtError } from './errors';

const defaultLoopConfig = {
DONT_LOG_ERRORS_ON_HANDLED_FAILURES: false,
ENABLE_THUNK_MIGRATION: false
ENABLE_THUNK_MIGRATION: false,
};

export function install(config = {}) {
const loopConfig = Object.assign({}, defaultLoopConfig, config);

return next => (reducer, initialState, enhancer) => {
return (next) => (reducer, initialState, enhancer) => {
const [initialModel, initialCmd] = liftState(initialState);
let cmdsQueue = [];

const liftReducer = reducer => (state, action) => {
const liftReducer = (reducer) => (state, action) => {
const result = reducer(state, action);
const [model, cmd] = liftState(result);
cmdsQueue.push({ originalAction: action, cmd });
Expand All @@ -24,7 +24,7 @@ export function install(config = {}) {
const store = next(liftReducer(reducer), initialModel, enhancer);

function runCmds(queue) {
const promises = queue.map(runCmd).filter(x => x);
const promises = queue.map(runCmd).filter((x) => x);
if (promises.length === 0) {
return Promise.resolve();
} else if (promises.length === 1) {
Expand All @@ -42,13 +42,13 @@ export function install(config = {}) {
}

return cmdPromise
.then(actions => {
.then((actions) => {
if (!actions.length) {
return;
}
return Promise.all(actions.map(dispatch));
})
.catch(error => {
.catch((error) => {
console.error(loopPromiseCaughtError(originalAction.type, error));
throw error;
});
Expand All @@ -70,13 +70,13 @@ export function install(config = {}) {

runCmd({
originalAction: { type: '@@ReduxLoop/INIT' },
cmd: initialCmd
cmd: initialCmd,
});

return {
...store,
dispatch,
replaceReducer
replaceReducer,
};
};
}
8 changes: 4 additions & 4 deletions src/loop.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { throwInvariant } from './utils';
import Cmd, { isCmd } from './cmd';

export const isLoop = array => {
export const isLoop = (array) => {
return (
Array.isArray(array) &&
array.length === 2 &&
Expand All @@ -10,11 +10,11 @@ export const isLoop = array => {
);
};

export const getCmd = loop => {
export const getCmd = (loop) => {
return isLoop(loop) ? loop[1] : null;
};

export const getModel = loop => {
export const getModel = (loop) => {
return isLoop(loop) ? loop[0] : loop;
};

Expand All @@ -26,6 +26,6 @@ export const loop = (model, cmd) => {
return [model, cmd];
};

export const liftState = state => {
export const liftState = (state) => {
return isLoop(state) ? state : loop(state, Cmd.none);
};
2 changes: 1 addition & 1 deletion src/merge-child-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ export function DEPRECATED_mergeChildReducers(
}, initialState);

return loop(newState, batchCmds(cmds));
}
}
2 changes: 1 addition & 1 deletion src/reduce-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default (...reducers) => (prevState, action, ...args) => {
if (isLoop(result)) {
return {
newState: getModel(result),
cmds: [...prevResult.cmds, getCmd(result)]
cmds: [...prevResult.cmds, getCmd(result)],
};
}
return { newState: result, cmds: prevResult.cmds };
Expand Down
Loading

0 comments on commit 1f704fc

Please sign in to comment.