@@ -65,8 +65,14 @@ export type {
65
65
TaskResult ,
66
66
} from './types'
67
67
68
- const defaultWhen : MiddlewarePhase = 'afterReducer'
69
- const actualMiddlewarePhases = [ 'beforeReducer' , 'afterReducer' ] as const
68
+ //Overly-aggressive byte-shaving
69
+ const { assign } = Object
70
+
71
+ const beforeReducer = 'beforeReducer' as const
72
+ const afterReducer = 'afterReducer' as const
73
+
74
+ const defaultWhen : MiddlewarePhase = afterReducer
75
+ const actualMiddlewarePhases = [ beforeReducer , afterReducer ] as const
70
76
71
77
const createFork = ( parentAbortSignal : AbortSignal ) => {
72
78
return < T > ( taskExecutor : ForkedTaskExecutor < T > ) : ForkedTask < T > => {
@@ -162,19 +168,17 @@ const createTakePattern = <S>(
162
168
export const createListenerEntry : TypedCreateListenerEntry < unknown > = (
163
169
options : FallbackAddListenerOptions
164
170
) => {
165
- let predicate : ListenerPredicate < any , any >
166
- let type : string | undefined
167
-
168
- if ( 'type' in options ) {
169
- type = options . type
170
- predicate = ( action : any ) : action is any => action . type === type
171
- } else if ( 'actionCreator' in options ) {
172
- type = options . actionCreator ! . type
173
- predicate = options . actionCreator . match
174
- } else if ( 'matcher' in options ) {
175
- predicate = options . matcher
176
- } else if ( 'predicate' in options ) {
177
- predicate = options . predicate
171
+ let { type, actionCreator, matcher, predicate, listener } = options
172
+
173
+ if ( type ) {
174
+ predicate = createAction ( type ) . match
175
+ } else if ( actionCreator ) {
176
+ type = actionCreator ! . type
177
+ predicate = actionCreator . match
178
+ } else if ( matcher ) {
179
+ predicate = matcher
180
+ } else if ( predicate ) {
181
+ // pass
178
182
} else {
179
183
throw new Error (
180
184
'Creating a listener requires one of the known fields for matching against actions'
@@ -185,7 +189,7 @@ export const createListenerEntry: TypedCreateListenerEntry<unknown> = (
185
189
const entry : ListenerEntry < unknown > = {
186
190
when : options . when || defaultWhen ,
187
191
id,
188
- listener : options . listener ,
192
+ listener,
189
193
type,
190
194
predicate,
191
195
pendingSet : new Set < AbortController > ( ) ,
@@ -371,30 +375,33 @@ export function createActionListenerMiddleware<
371
375
try {
372
376
entry . pendingSet . add ( internalTaskController )
373
377
await Promise . resolve (
374
- entry . listener ( action , {
375
- ...api ,
376
- getOriginalState,
377
- condition,
378
- take,
379
- delay,
380
- pause,
381
- currentPhase,
382
- extra,
383
- signal : internalTaskController . signal ,
384
- fork,
385
- unsubscribe : entry . unsubscribe ,
386
- subscribe : ( ) => {
387
- listenerMap . set ( entry . id , entry )
388
- } ,
389
- cancelPrevious : ( ) => {
390
- entry . pendingSet . forEach ( ( controller , _ , set ) => {
391
- if ( controller !== internalTaskController ) {
392
- controller . abort ( )
393
- set . delete ( controller )
394
- }
395
- } )
396
- } ,
397
- } )
378
+ entry . listener (
379
+ action ,
380
+ // Use assign() rather than ... to avoid extra helper functions added to bundle
381
+ assign ( { } , api , {
382
+ getOriginalState,
383
+ condition,
384
+ take,
385
+ delay,
386
+ pause,
387
+ currentPhase,
388
+ extra,
389
+ signal : internalTaskController . signal ,
390
+ fork,
391
+ unsubscribe : entry . unsubscribe ,
392
+ subscribe : ( ) => {
393
+ listenerMap . set ( entry . id , entry )
394
+ } ,
395
+ cancelPrevious : ( ) => {
396
+ entry . pendingSet . forEach ( ( controller , _ , set ) => {
397
+ if ( controller !== internalTaskController ) {
398
+ controller . abort ( )
399
+ set . delete ( controller )
400
+ }
401
+ } )
402
+ } ,
403
+ } )
404
+ )
398
405
)
399
406
} catch ( listenerError ) {
400
407
if ( ! ( listenerError instanceof TaskAbortError ) ) {
@@ -467,15 +474,15 @@ export function createActionListenerMiddleware<
467
474
468
475
notifyListener ( entry , action , api , getOriginalState , currentPhase )
469
476
}
470
- if ( currentPhase === ' beforeReducer' ) {
477
+ if ( currentPhase === beforeReducer ) {
471
478
result = next ( action )
472
479
} else {
473
480
return result
474
481
}
475
482
}
476
483
}
477
484
478
- return Object . assign (
485
+ return assign (
479
486
middleware ,
480
487
{
481
488
addListener,
0 commit comments