Skip to content

Commit

Permalink
eslint cleanup and source formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbski committed Jul 8, 2020
1 parent d89fd2c commit 35455c4
Show file tree
Hide file tree
Showing 8 changed files with 1,060 additions and 1,717 deletions.
6 changes: 3 additions & 3 deletions .eslintrc
Expand Up @@ -8,9 +8,11 @@
"comma-dangle": 0,
"consistent-return": 1,
// causing issues with codacy
"function-paren-newline": "off",
"import/no-unresolved": 0,
"indent": 0,
"implicit-arrow-linebreak": 0,
"max-len": "off",
"no-multi-spaces": 0,
"no-nested-ternary": 0,
"no-plusplus": 0,
Expand All @@ -37,7 +39,5 @@
"parserOptions": {
"ecmaVersion": 9
},
"plugins": [
"react"
]
"plugins": ["react"]
}
6 changes: 6 additions & 0 deletions .prettierrc.js
@@ -0,0 +1,6 @@
module.exports = {
tabWidth: 2,
singleQuote: true,
printWidth: 120,
trailingComma: 'none',
};
63 changes: 39 additions & 24 deletions src/createLogicAction$.js
@@ -1,6 +1,5 @@
import isPromise from 'is-promise';
import { Observable, Subject } from 'rxjs';
import { take, takeUntil} from 'rxjs/operators';
import { Observable } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators';
import { identityFn, wrapActionForIntercept } from './utils';
import createDepObject from './createDepObject';
import execProcessFn from './execProcessFn';
Expand All @@ -9,42 +8,56 @@ import createCancelled$ from './createCancelled$';

const debug = (/* ...args */) => {};

export default function createLogicAction$({ action, logic, store, deps,
cancel$, monitor$, action$ }) {
export default function createLogicAction$({ action, logic, store, deps, cancel$, monitor$, action$ }) {
const { getState } = store;
const { name, process: processFn, processOptions: { dispatchReturn,
dispatchMultiple, successType, failType } } = logic;
const {
name,
process: processFn,
processOptions: { dispatchReturn }
} = logic;
const intercept = logic.validate || logic.transform; // aliases

debug('createLogicAction$', name, action);
monitor$.next({ action, name, op: 'begin' }); // also in logicWrapper

const logicActionOps = [
(cancel$) ? takeUntil(cancel$) : null, // only takeUntil if cancel or latest
cancel$ ? takeUntil(cancel$) : null, // only takeUntil if cancel or latest
take(1)
].filter(identityFn);

// logicAction$ is used for the mw next(action) call
const logicAction$ = Observable.create(logicActionObs => {
const logicAction$ = Observable.create((logicActionObs) => {
// create notification subject for process which we dispose of
// when take(1) or when we are done dispatching
const { cancelled$, setInterceptComplete } = createCancelled$({
action, cancel$, monitor$, logic });
action,
cancel$,
monitor$,
logic
});

const { dispatch, dispatch$, done } = createDispatch({
action, cancel$, cancelled$, logic, monitor$, store });
action,
cancel$,
cancelled$,
logic,
monitor$,
store
});

// passed into each execution phase hook as first argument
const ctx = {}; // for sharing data between hooks
const depObj = createDepObject({ deps, cancelled$, ctx, getState, action, action$ });


function shouldDispatch(act, useDispatch) {
if (!act) { return false; }
if (useDispatch === 'auto') { // dispatch on diff type
return (act.type !== action.type);
if (!act) {
return false;
}
if (useDispatch === 'auto') {
// dispatch on diff type
return act.type !== action.type;
}
return (useDispatch); // otherwise forced truthy/falsy
return useDispatch; // otherwise forced truthy/falsy
}

const AllowRejectNextDefaults = {
Expand All @@ -66,7 +79,6 @@ export default function createLogicAction$({ action, logic, store, deps,
handleNextOrDispatch(false, act, options);
}


function handleNextOrDispatch(shouldProcess, act, options) {
const shouldProcessAndHasProcessFn = shouldProcess && processFn;
const { useDispatch } = applyAllowRejectNextDefaults(options);
Expand All @@ -75,32 +87,35 @@ export default function createLogicAction$({ action, logic, store, deps,
setInterceptComplete();
dispatch(wrapActionForIntercept(act), { allowMore: true }); // will be completed later
logicActionObs.complete(); // dispatched action, so no next(act)
} else { // normal next
} else {
// normal next
if (act) {
monitor$.next({ action, nextAction: act, name, shouldProcess, op: 'next' });
} else { // act is undefined, filtered
} else {
// act is undefined, filtered
monitor$.next({ action, name, shouldProcess, op: 'filtered' });
setInterceptComplete();
}
postIfDefinedOrComplete(act, logicActionObs);
}

// unless rejected, we will process even if allow/next dispatched
if (shouldProcessAndHasProcessFn) { // processing, was an accept
if (shouldProcessAndHasProcessFn) {
// processing, was an accept
// if action provided is empty, give process orig
depObj.action = act || action;

execProcessFn({ depObj, dispatch, done, processFn,
dispatchReturn, dispatch$, name });
} else { // not processing, must have been a reject
execProcessFn({ depObj, dispatch, done, processFn, dispatchReturn, dispatch$, name });
} else {
// not processing, must have been a reject
dispatch$.complete();
}
}

/* post if defined, then complete */
function postIfDefinedOrComplete(act, act$) {
if (act) {
act$.next(act); // triggers call to middleware's next()
act$.next(act); // triggers call to middleware's next()
}
setInterceptComplete();
act$.complete();
Expand Down

0 comments on commit 35455c4

Please sign in to comment.