@@ -53,7 +53,7 @@ import { addSubscription, triggerSubscriptions, noop } from './subscriptions'
53
53
54
54
const fallbackRunWithContext = ( fn : ( ) => unknown ) => fn ( )
55
55
56
- type _ArrayType < AT > = AT extends Array < infer T > ? T : never
56
+ type _SetType < AT > = AT extends Set < infer T > ? T : never
57
57
58
58
/**
59
59
* Marks a function as an action for `$onAction`
@@ -267,8 +267,8 @@ function createSetupStore<
267
267
// internal state
268
268
let isListening : boolean // set to true at the end
269
269
let isSyncListening : boolean // set to true at the end
270
- let subscriptions : SubscriptionCallback < S > [ ] = [ ]
271
- let actionSubscriptions : StoreOnActionListener < Id , S , G , A > [ ] = [ ]
270
+ let subscriptions : Set < SubscriptionCallback < S > > = new Set ( )
271
+ let actionSubscriptions : Set < StoreOnActionListener < Id , S , G , A > > = new Set ( )
272
272
let debuggerEvents : DebuggerEvent [ ] | DebuggerEvent
273
273
const initialState = pinia . state . value [ $id ] as UnwrapRef < S > | undefined
274
274
@@ -350,8 +350,8 @@ function createSetupStore<
350
350
351
351
function $dispose ( ) {
352
352
scope . stop ( )
353
- subscriptions = [ ]
354
- actionSubscriptions = [ ]
353
+ subscriptions . clear ( )
354
+ actionSubscriptions . clear ( )
355
355
pinia . _s . delete ( $id )
356
356
}
357
357
@@ -371,13 +371,13 @@ function createSetupStore<
371
371
setActivePinia ( pinia )
372
372
const args = Array . from ( arguments )
373
373
374
- const afterCallbackList : Array < ( resolvedReturn : any ) => any > = [ ]
375
- const onErrorCallbackList : Array < ( error : unknown ) => unknown > = [ ]
376
- function after ( callback : _ArrayType < typeof afterCallbackList > ) {
377
- afterCallbackList . push ( callback )
374
+ const afterCallbackSet : Set < ( resolvedReturn : any ) => any > = new Set ( )
375
+ const onErrorCallbackSet : Set < ( error : unknown ) => unknown > = new Set ( )
376
+ function after ( callback : _SetType < typeof afterCallbackSet > ) {
377
+ afterCallbackSet . add ( callback )
378
378
}
379
- function onError ( callback : _ArrayType < typeof onErrorCallbackList > ) {
380
- onErrorCallbackList . push ( callback )
379
+ function onError ( callback : _SetType < typeof onErrorCallbackSet > ) {
380
+ onErrorCallbackSet . add ( callback )
381
381
}
382
382
383
383
// @ts -expect-error
@@ -394,24 +394,24 @@ function createSetupStore<
394
394
ret = fn . apply ( this && this . $id === $id ? this : store , args )
395
395
// handle sync errors
396
396
} catch ( error ) {
397
- triggerSubscriptions ( onErrorCallbackList , error )
397
+ triggerSubscriptions ( onErrorCallbackSet , error )
398
398
throw error
399
399
}
400
400
401
401
if ( ret instanceof Promise ) {
402
402
return ret
403
403
. then ( ( value ) => {
404
- triggerSubscriptions ( afterCallbackList , value )
404
+ triggerSubscriptions ( afterCallbackSet , value )
405
405
return value
406
406
} )
407
407
. catch ( ( error ) => {
408
- triggerSubscriptions ( onErrorCallbackList , error )
408
+ triggerSubscriptions ( onErrorCallbackSet , error )
409
409
return Promise . reject ( error )
410
410
} )
411
411
}
412
412
413
413
// trigger after callbacks
414
- triggerSubscriptions ( afterCallbackList , ret )
414
+ triggerSubscriptions ( afterCallbackSet , ret )
415
415
return ret
416
416
} as MarkedAction < Fn >
417
417
0 commit comments