From bb1b1b4f9da8831cbd0e777307837e04dd60e105 Mon Sep 17 00:00:00 2001 From: Miroslav Petrik Date: Thu, 7 Mar 2024 17:29:17 +0100 Subject: [PATCH] fix: remove unnecessary wrapping for fields The fields object was previously necessary when list of fieldAtoms was permissible. --- src/atoms/list-atom/listAtom.ts | 16 ++++------------ src/atoms/list-atom/listItemForm.ts | 6 ++---- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/atoms/list-atom/listAtom.ts b/src/atoms/list-atom/listAtom.ts index 3e6a3cf..fe60048 100644 --- a/src/atoms/list-atom/listAtom.ts +++ b/src/atoms/list-atom/listAtom.ts @@ -133,10 +133,7 @@ export function listAtom< const formLists = get(_formListAtom); return formLists.map((formAtom) => { - const formAtoms = get(formAtom); - const { fields } = get(formAtoms.fields); - - return fields; + return get(get(formAtom).fields); }); }); @@ -214,14 +211,9 @@ export function listAtom< const emptyAtom = atom((get) => get(_formListAtom).length === 0); const valueAtom = atom( (get) => { - const formLists = get(_formListAtom); - - return formLists.map((formAtom) => { - const formAtoms = get(formAtom); - const { fields } = get(formAtoms.values); - - return fields as Value; - }); + return get(_formListAtom).map((formAtom) => { + return get(get(formAtom).values); + }) as Value[]; }, ( get, diff --git a/src/atoms/list-atom/listItemForm.ts b/src/atoms/list-atom/listItemForm.ts index d3dd016..161d1a5 100644 --- a/src/atoms/list-atom/listItemForm.ts +++ b/src/atoms/list-atom/listItemForm.ts @@ -97,9 +97,7 @@ type NamedFormAtom = Atom<{ ) => Promise; }>; -export type ListItemForm = NamedFormAtom<{ - fields: Fields; -}>; +export type ListItemForm = NamedFormAtom; export function listItemForm({ fields, @@ -132,7 +130,7 @@ export function listItemForm({ >; }) { const itemFormAtom: ListItemForm = extendAtom( - formAtom({ fields }) as unknown as PrimitiveFormAtom, + formAtom(fields) as unknown as PrimitiveFormAtom, (base, get) => { const nameAtom = atom((get) => { const list: ListItemForm[] = get(formListAtom);