Skip to content

Commit 7a3d44c

Browse files
arthurxavierxmaddie927
authored andcommitted
Fix unsafe props assignment in Wizard (#84)
1 parent 237a0a5 commit 7a3d44c

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

docs/Examples/Wizard.example.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ docs = unit # make (createComponent "WizardExample") { initialState, render }
7070
, onChange: send self <<< OnChange
7171
, forceTopLabels: false
7272
, inlineTable: false
73-
, readonly: false
73+
, formProps: { readonly: false }
7474
}
7575
, row
7676
{ style: R.css { justifyContent: "flex-end" }

src/Lumi/Components/Wizard.purs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import Effect (Effect)
2222
import Lumi.Components.Form (FormBuilder)
2323
import Lumi.Components.Form as F
2424
import React.Basic (JSX)
25-
import Record.Unsafe.Union (unsafeUnion)
26-
import Unsafe.Coerce (unsafeCoerce)
2725

2826
-- | `Form` is the base functor for the `Wizard` language. It represents a
2927
-- | form as a step of the wizard, taking a parametrized identifier for the
@@ -68,15 +66,16 @@ step s f =
6866
Wizard $ liftF $ Form
6967
{ step: s
7068
, run:
71-
\props value ->
69+
\formProps value ->
7270
{ form: \{ forceTopLabels, inlineTable } onChange ->
73-
form $ unsafeUnion props
71+
form
7472
{ value
75-
, onChange: \_ -> onChange
73+
, onChange
7674
, forceTopLabels
7775
, inlineTable
76+
, formProps
7877
}
79-
, result: F.revalidate f props value
78+
, result: F.revalidate f formProps value
8079
}
8180
}
8281

@@ -181,31 +180,20 @@ gotoStep s w props value = go (liftStep w)
181180
-- | A component that renders a `WizardStep` (a suspended `Wizard`).
182181
wizard
183182
:: forall step props value a
184-
. { step :: WizardStep step {| props } value a
183+
. { step :: WizardStep step props value a
185184
, value :: value
186185
, onChange :: (value -> value) -> Effect Unit
187186
, forceTopLabels :: Boolean
188187
, inlineTable :: Boolean
189-
| props
188+
, formProps :: props
190189
}
191190
-> JSX
192-
wizard props@{ value, onChange, forceTopLabels, inlineTable } =
191+
wizard props@{ value, onChange, forceTopLabels, inlineTable, formProps } =
193192
case (un WizardStep props.step).current of
194193
Right a ->
195194
mempty
196195
Left (Form form') ->
197196
let
198-
{ form } = form'.run (contractProps props) value
197+
{ form } = form'.run formProps value
199198
in
200199
form { forceTopLabels, inlineTable } onChange
201-
where
202-
contractProps
203-
:: { step :: WizardStep step {| props } value a
204-
, value :: value
205-
, onChange :: (value -> value) -> Effect Unit
206-
, forceTopLabels :: Boolean
207-
, inlineTable :: Boolean
208-
| props
209-
}
210-
-> {| props }
211-
contractProps = unsafeCoerce

0 commit comments

Comments
 (0)