Skip to content

Commit 5e70935

Browse files
committed
Merge branch 'remove-delay'
2 parents fa2eed9 + 99e7c9d commit 5e70935

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

src/createLogicAction$.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import isObservable from 'is-observable';
22
import isPromise from 'is-promise';
33
import { Observable } from 'rxjs/Observable';
44
import { Subject } from 'rxjs/Subject';
5-
import { asap } from 'rxjs/scheduler/asap';
65
import 'rxjs/add/observable/from';
76
import 'rxjs/add/observable/of';
87
import 'rxjs/add/operator/catch';
98
import 'rxjs/add/operator/do';
109
import 'rxjs/add/operator/filter';
1110
import 'rxjs/add/operator/map';
1211
import 'rxjs/add/operator/mergeAll';
13-
import 'rxjs/add/operator/observeOn';
1412
import 'rxjs/add/operator/take';
1513
import 'rxjs/add/operator/takeUntil';
1614

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

189187
// unless rejected, we will process even if allow/next dispatched
190188
if (shouldProcess) { // processing, was an accept
191-
// delay process slightly so state can be updated
192-
Observable.of(true)
193-
.observeOn(asap)
194-
.subscribe(() => {
195-
// if action provided is empty, give process orig
196-
depObj.action = act || action;
197-
try {
198-
const retValue = processFn(depObj, dispatch, done);
199-
if (dispatchReturn) { // processOption.dispatchReturn true
200-
handleDispatchReturn(retValue);
201-
}
202-
} catch (err) {
203-
dispatch(err);
204-
}
205-
});
189+
// if action provided is empty, give process orig
190+
depObj.action = act || action;
191+
try {
192+
const retValue = processFn(depObj, dispatch, done);
193+
if (dispatchReturn) { // processOption.dispatchReturn true
194+
handleDispatchReturn(retValue);
195+
}
196+
} catch (err) {
197+
dispatch(err);
198+
}
206199
} else { // not processing, must have been a reject
207200
dispatch$.complete();
208201
}

test/createLogicMiddleware-integrated.spec.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ describe('createLogicMiddleware-integration', () => {
5151

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

@@ -69,6 +71,7 @@ describe('createLogicMiddleware-integration', () => {
6971
shouldProcess: true,
7072
op: 'next' },
7173
{ nextAction: { type: 'DEC' }, op: 'bottom' },
74+
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
7275
{ action: { type: 'DEC' }, op: 'top' },
7376
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'begin' },
7477
{ action: { type: 'DEC' },
@@ -81,7 +84,6 @@ describe('createLogicMiddleware-integration', () => {
8184
op: 'dispatch' },
8285
{ action: { type: 'NOOP' }, op: 'top' },
8386
{ nextAction: { type: 'NOOP' }, op: 'bottom' },
84-
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
8587
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' }
8688
]);
8789
});
@@ -175,6 +177,8 @@ describe('createLogicMiddleware-integration', () => {
175177
shouldProcess: true,
176178
op: 'next' },
177179
{ nextAction: { type: 'DEC' }, op: 'bottom' },
180+
{ action: { type: 'DEC' }, name: 'L(*)-1', op: 'end' },
181+
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
178182
{ action: { type: 'DEC' }, op: 'top' },
179183
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'begin' },
180184
{ action: { type: 'DEC' },
@@ -193,6 +197,7 @@ describe('createLogicMiddleware-integration', () => {
193197
shouldProcess: true,
194198
op: 'next' },
195199
{ nextAction: { type: 'NOOP' }, op: 'bottom' },
200+
{ action: { type: 'NOOP' }, name: 'L(*)-1', op: 'end' },
196201
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
197202
{ action: { type: 'DEC' }, op: 'top' },
198203
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'begin' },
@@ -212,6 +217,7 @@ describe('createLogicMiddleware-integration', () => {
212217
shouldProcess: true,
213218
op: 'next' },
214219
{ nextAction: { type: 'NOOP' }, op: 'bottom' },
220+
{ action: { type: 'NOOP' }, name: 'L(*)-1', op: 'end' },
215221
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
216222
{ action: { type: 'DEC' }, op: 'top' },
217223
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'begin' },
@@ -231,12 +237,8 @@ describe('createLogicMiddleware-integration', () => {
231237
shouldProcess: true,
232238
op: 'next' },
233239
{ nextAction: { type: 'NOOP' }, op: 'bottom' },
234-
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
235-
{ action: { type: 'DEC' }, name: 'L(*)-1', op: 'end' },
236-
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' },
237240
{ action: { type: 'NOOP' }, name: 'L(*)-1', op: 'end' },
238-
{ action: { type: 'NOOP' }, name: 'L(*)-1', op: 'end' },
239-
{ action: { type: 'NOOP' }, name: 'L(*)-1', op: 'end' }
241+
{ action: { type: 'DEC' }, name: 'L(DEC)-0', op: 'end' }
240242
]);
241243
});
242244

test/createLogicMiddleware-latest.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,13 @@ describe('createLogicMiddleware-latest', () => {
491491
shouldProcess: true,
492492
op: 'next' },
493493
{ nextAction: { type: 'FOO', id: 2 }, op: 'bottom' },
494+
{ action: { type: 'FOO', id: 2 },
495+
dispAction: { type: 'BAR', id: 2 },
496+
op: 'dispatch' },
494497
{ action: { type: 'FOO', id: 1 },
495498
name: 'L(FOO)-0',
496499
op: 'dispCancelled' },
497500
{ action: { type: 'FOO', id: 1 }, name: 'L(FOO)-0', op: 'end' },
498-
{ action: { type: 'FOO', id: 2 },
499-
dispAction: { type: 'BAR', id: 2 },
500-
op: 'dispatch' },
501501
{ action: { type: 'FOO', id: 2 },
502502
dispAction: { type: 'CAT', id: 2 },
503503
op: 'dispatch' },
@@ -544,7 +544,7 @@ describe('createLogicMiddleware-latest', () => {
544544
type: 'CAT'
545545
});
546546
obs.complete();
547-
}, 10);
547+
}, 30);
548548
}));
549549
}
550550
});
@@ -592,13 +592,13 @@ describe('createLogicMiddleware-latest', () => {
592592
shouldProcess: true,
593593
op: 'next' },
594594
{ nextAction: { type: 'FOO', id: 2 }, op: 'bottom' },
595+
{ action: { type: 'FOO', id: 2 },
596+
dispAction: { type: 'BAR', id: 2 },
597+
op: 'dispatch' },
595598
{ action: { type: 'FOO', id: 1 },
596599
name: 'L(FOO)-0',
597600
op: 'dispCancelled' },
598601
{ action: { type: 'FOO', id: 1 }, name: 'L(FOO)-0', op: 'end' },
599-
{ action: { type: 'FOO', id: 2 },
600-
dispAction: { type: 'BAR', id: 2 },
601-
op: 'dispatch' },
602602
{ action: { type: 'FOO', id: 2 },
603603
dispAction: { type: 'CAT', id: 2 },
604604
op: 'dispatch' },

0 commit comments

Comments
 (0)