Skip to content

Commit

Permalink
Merge branch 'remove-delay'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbski committed Jan 16, 2017
2 parents fa2eed9 + 99e7c9d commit 5e70935
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
27 changes: 10 additions & 17 deletions src/createLogicAction$.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import isObservable from 'is-observable';
import isPromise from 'is-promise';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { asap } from 'rxjs/scheduler/asap';
import 'rxjs/add/observable/from';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeAll';
import 'rxjs/add/operator/observeOn';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/takeUntil';

Expand Down Expand Up @@ -188,21 +186,16 @@ export default function createLogicAction$({ action, logic, store, deps, cancel$

// unless rejected, we will process even if allow/next dispatched
if (shouldProcess) { // processing, was an accept
// delay process slightly so state can be updated
Observable.of(true)
.observeOn(asap)
.subscribe(() => {
// if action provided is empty, give process orig
depObj.action = act || action;
try {
const retValue = processFn(depObj, dispatch, done);
if (dispatchReturn) { // processOption.dispatchReturn true
handleDispatchReturn(retValue);
}
} catch (err) {
dispatch(err);
}
});
// if action provided is empty, give process orig
depObj.action = act || action;
try {
const retValue = processFn(depObj, dispatch, done);
if (dispatchReturn) { // processOption.dispatchReturn true
handleDispatchReturn(retValue);
}
} catch (err) {
dispatch(err);
}
} else { // not processing, must have been a reject
dispatch$.complete();
}
Expand Down
14 changes: 8 additions & 6 deletions test/createLogicMiddleware-integrated.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ describe('createLogicMiddleware-integration', () => {

store.dispatch({ type: 'DEC' });
store.dispatch({ type: 'DEC' });
// we could just call done() here since everything is sync
// but whenComplete is always the safe thing to do
logicMiddleware.whenComplete(done);
});

Expand All @@ -69,6 +71,7 @@ describe('createLogicMiddleware-integration', () => {
shouldProcess: true,
op: 'next' },
{ nextAction: { type: 'DEC' }, op: 'bottom' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
{ action: { type: 'DEC' }, op: 'top' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'begin' },
{ action: { type: 'DEC' },
Expand All @@ -81,7 +84,6 @@ describe('createLogicMiddleware-integration', () => {
op: 'dispatch' },
{ action: { type: 'NOOP' }, op: 'top' },
{ nextAction: { type: 'NOOP' }, op: 'bottom' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' }
]);
});
Expand Down Expand Up @@ -175,6 +177,8 @@ describe('createLogicMiddleware-integration', () => {
shouldProcess: true,
op: 'next' },
{ nextAction: { type: 'DEC' }, op: 'bottom' },
{ action: { type: 'DEC' }, name: 'L(*)-1', op: 'end' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
{ action: { type: 'DEC' }, op: 'top' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'begin' },
{ action: { type: 'DEC' },
Expand All @@ -193,6 +197,7 @@ describe('createLogicMiddleware-integration', () => {
shouldProcess: true,
op: 'next' },
{ nextAction: { type: 'NOOP' }, op: 'bottom' },
{ action: { type: 'NOOP' }, name: 'L(*)-1', op: 'end' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
{ action: { type: 'DEC' }, op: 'top' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'begin' },
Expand All @@ -212,6 +217,7 @@ describe('createLogicMiddleware-integration', () => {
shouldProcess: true,
op: 'next' },
{ nextAction: { type: 'NOOP' }, op: 'bottom' },
{ action: { type: 'NOOP' }, name: 'L(*)-1', op: 'end' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
{ action: { type: 'DEC' }, op: 'top' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'begin' },
Expand All @@ -231,12 +237,8 @@ describe('createLogicMiddleware-integration', () => {
shouldProcess: true,
op: 'next' },
{ nextAction: { type: 'NOOP' }, op: 'bottom' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
{ action: { type: 'DEC' }, name: 'L(*)-1', op: 'end' },
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
{ action: { type: 'NOOP' }, name: 'L(*)-1', op: 'end' },
{ action: { type: 'NOOP' }, name: 'L(*)-1', op: 'end' },
{ action: { type: 'NOOP' }, name: 'L(*)-1', op: 'end' }
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' }
]);
});

Expand Down
14 changes: 7 additions & 7 deletions test/createLogicMiddleware-latest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,13 @@ describe('createLogicMiddleware-latest', () => {
shouldProcess: true,
op: 'next' },
{ nextAction: { type: 'FOO', id: 2 }, op: 'bottom' },
{ action: { type: 'FOO', id: 2 },
dispAction: { type: 'BAR', id: 2 },
op: 'dispatch' },
{ action: { type: 'FOO', id: 1 },
name: 'L(FOO)-0',
op: 'dispCancelled' },
{ action: { type: 'FOO', id: 1 }, name: 'L(FOO)-0', op: 'end' },
{ action: { type: 'FOO', id: 2 },
dispAction: { type: 'BAR', id: 2 },
op: 'dispatch' },
{ action: { type: 'FOO', id: 2 },
dispAction: { type: 'CAT', id: 2 },
op: 'dispatch' },
Expand Down Expand Up @@ -544,7 +544,7 @@ describe('createLogicMiddleware-latest', () => {
type: 'CAT'
});
obs.complete();
}, 10);
}, 30);
}));
}
});
Expand Down Expand Up @@ -592,13 +592,13 @@ describe('createLogicMiddleware-latest', () => {
shouldProcess: true,
op: 'next' },
{ nextAction: { type: 'FOO', id: 2 }, op: 'bottom' },
{ action: { type: 'FOO', id: 2 },
dispAction: { type: 'BAR', id: 2 },
op: 'dispatch' },
{ action: { type: 'FOO', id: 1 },
name: 'L(FOO)-0',
op: 'dispCancelled' },
{ action: { type: 'FOO', id: 1 }, name: 'L(FOO)-0', op: 'end' },
{ action: { type: 'FOO', id: 2 },
dispAction: { type: 'BAR', id: 2 },
op: 'dispatch' },
{ action: { type: 'FOO', id: 2 },
dispAction: { type: 'CAT', id: 2 },
op: 'dispatch' },
Expand Down

0 comments on commit 5e70935

Please sign in to comment.