Skip to content

Commit 63b4c93

Browse files
authored
Merge branch 'main' into fix/utils/atom-with-observable
2 parents 6a9d6e4 + d06e958 commit 63b4c93

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

examples/mega-form/src/useAtomSlice.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ import type { PrimitiveAtom } from 'jotai'
44
import { splitAtom } from 'jotai/utils'
55

66
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+
)
810
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],
1120
)
1221
}
1322

src/vanilla/internals.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,16 +457,12 @@ const buildStore = (
457457
const flushCallbacks =
458458
buildingBlockFunctions[1] ||
459459
(() => {
460-
let hasError: true | undefined
461-
let error: unknown | undefined
460+
const errors: unknown[] = []
462461
const call = (fn: () => void) => {
463462
try {
464463
fn()
465464
} catch (e) {
466-
if (!hasError) {
467-
hasError = true
468-
error = e
469-
}
465+
errors.push(e)
470466
}
471467
}
472468
do {
@@ -490,8 +486,8 @@ const buildStore = (
490486
unmountCallbacks.size ||
491487
mountCallbacks.size
492488
)
493-
if (hasError) {
494-
throw error
489+
if (errors.length) {
490+
throw new AggregateError(errors)
495491
}
496492
})
497493

0 commit comments

Comments
 (0)