Skip to content

Commit a7a817d

Browse files
committed
Change type signature of append in useFieldArray hook
1 parent 9369139 commit a7a817d

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# v0.0.4 (unreleased)
1+
# v0.0.4
2+
3+
- Change type signature of append in useFieldArray hook
4+
- Updated from `t => unit` to `defaultValuesOfT => unit`
5+
- This change provides better type flexibility when appending new items to the array
26

37
# v0.0.3
48

doc/transformation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module ControllerOfInputs = {
9090
// useFieldArray
9191
type rec useFieldArrayReturnOfInputsCart = {
9292
fields: array<itemWithId>,
93-
append: item => unit,
93+
append: defaultValuesOfItem => unit,
9494
remove: int => unit,
9595
}
9696
and useFieldArrayParamsOfInputsCart = {

src/ppx/signature.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ let map_type_decl
602602
[
603603
(* type useFieldArrayReturnOfInputsCart = {
604604
fields: array<itemWithId>,
605-
append: item => unit,
605+
append: defaultValuesOfItem => unit,
606606
remove: int => unit,
607607
} *)
608608
Type.mk
@@ -628,7 +628,11 @@ let map_type_decl
628628
(uncurried_core_type_arrow ~arity:1
629629
[
630630
Typ.arrow Nolabel
631-
(Typ.constr (lid item_name) [])
631+
(Typ.constr
632+
(lid
633+
("defaultValuesOf"
634+
^ capitalize item_name))
635+
[])
632636
(Typ.constr (lid "unit") []);
633637
]);
634638
Type.field ~mut:Immutable

src/ppx/structure.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ let map_type_decl
602602
[
603603
(* type useFieldArrayReturnOfInputsCart = {
604604
fields: array<itemWithId>,
605-
append: item => unit,
605+
append: defaultValuesOfItem => unit,
606606
remove: int => unit,
607607
} *)
608608
Type.mk
@@ -628,7 +628,11 @@ let map_type_decl
628628
(uncurried_core_type_arrow ~arity:1
629629
[
630630
Typ.arrow Nolabel
631-
(Typ.constr (lid item_name) [])
631+
(Typ.constr
632+
(lid
633+
("defaultValuesOf"
634+
^ capitalize item_name))
635+
[])
632636
(Typ.constr (lid "unit") []);
633637
]);
634638
Type.field ~mut:Immutable

test/src/pages/field_array_res/FieldArray.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let default = () => {
5050
</div>
5151
})
5252
->React.array}
53-
<button type_="button" onClick={_ => append({name: "ppx", quantity: 1., price: 1.})}>
53+
<button type_="button" onClick={_ => append({quantity: 1., price: 1.})}>
5454
{"APPEND"->React.string}
5555
</button>
5656
<input type_="submit" />

0 commit comments

Comments
 (0)