Skip to content

Commit

Permalink
fix: remove unnecessary wrapping for fields
Browse files Browse the repository at this point in the history
The fields object was previously necessary when list of fieldAtoms was permissible.
  • Loading branch information
MiroslavPetrik committed Mar 7, 2024
1 parent b04e297 commit bb1b1b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
16 changes: 4 additions & 12 deletions src/atoms/list-atom/listAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions src/atoms/list-atom/listItemForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ type NamedFormAtom<Fields extends FormFields> = Atom<{
) => Promise<void>;
}>;

export type ListItemForm<Fields extends FormFields> = NamedFormAtom<{
fields: Fields;
}>;
export type ListItemForm<Fields extends FormFields> = NamedFormAtom<Fields>;

export function listItemForm<Fields extends FormFields>({
fields,
Expand Down Expand Up @@ -132,7 +130,7 @@ export function listItemForm<Fields extends FormFields>({
>;
}) {
const itemFormAtom: ListItemForm<Fields> = extendAtom(
formAtom({ fields }) as unknown as PrimitiveFormAtom<Fields>,
formAtom(fields) as unknown as PrimitiveFormAtom<Fields>,
(base, get) => {
const nameAtom = atom((get) => {
const list: ListItemForm<Fields>[] = get(formListAtom);
Expand Down

0 comments on commit bb1b1b4

Please sign in to comment.