File tree 2 files changed +16
-11
lines changed
2 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,19 @@ import type { PrimitiveAtom } from 'jotai'
4
4
import { splitAtom } from 'jotai/utils'
5
5
6
6
const useAtomSlice = < Item > ( arrAtom : PrimitiveAtom < Item [ ] > ) => {
7
- const [ atoms , remove ] = useAtom ( useMemo ( ( ) => splitAtom ( arrAtom ) , [ arrAtom ] ) )
7
+ const [ atoms , dispatch ] = useAtom (
8
+ useMemo ( ( ) => splitAtom ( arrAtom ) , [ arrAtom ] ) ,
9
+ )
8
10
return useMemo (
9
- ( ) => atoms . map ( ( itemAtom ) => [ itemAtom , ( ) => remove ( itemAtom ) ] as const ) ,
10
- [ atoms , remove ] ,
11
+ ( ) =>
12
+ atoms . map (
13
+ ( itemAtom ) =>
14
+ [
15
+ itemAtom ,
16
+ ( ) => dispatch ( { type : 'remove' , atom : itemAtom } ) ,
17
+ ] as const ,
18
+ ) ,
19
+ [ atoms , dispatch ] ,
11
20
)
12
21
}
13
22
Original file line number Diff line number Diff line change @@ -457,16 +457,12 @@ const buildStore = (
457
457
const flushCallbacks =
458
458
buildingBlockFunctions [ 1 ] ||
459
459
( ( ) => {
460
- let hasError : true | undefined
461
- let error : unknown | undefined
460
+ const errors : unknown [ ] = [ ]
462
461
const call = ( fn : ( ) => void ) => {
463
462
try {
464
463
fn ( )
465
464
} catch ( e ) {
466
- if ( ! hasError ) {
467
- hasError = true
468
- error = e
469
- }
465
+ errors . push ( e )
470
466
}
471
467
}
472
468
do {
@@ -490,8 +486,8 @@ const buildStore = (
490
486
unmountCallbacks . size ||
491
487
mountCallbacks . size
492
488
)
493
- if ( hasError ) {
494
- throw error
489
+ if ( errors . length ) {
490
+ throw new AggregateError ( errors )
495
491
}
496
492
} )
497
493
You can’t perform that action at this time.
0 commit comments