Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in Reset #43

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/Formless/Component.purs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ component =
, submitAttempts: 0
, submitting: false
, form: Internal.inputFieldsToFormFields initialInputs
, internal: InternalState
, internal: InternalState
{ allTouched: false
, initialInputs
, validators
, validators
, debounceRef: Nothing
}
}
Expand All @@ -84,12 +84,12 @@ component =
eval = case _ of
Initialize a -> do
ref <- H.liftEffect $ Ref.new Nothing
modifyState_ \st -> st
modifyState_ \st -> st
{ internal = over InternalState (_ { debounceRef = Just ref }) st.internal }
pure a

Modify variant a -> do
modifyState_ \st -> st
modifyState_ \st -> st
{ form = Internal.unsafeModifyInputVariant identity variant st.form }
eval $ SyncFormData a

Expand All @@ -102,8 +102,8 @@ component =

-- Provided as a separate query to minimize state updates / re-renders
ModifyValidate milliseconds variant a -> do
let
modifyWith
let
modifyWith
:: (forall e o. FormFieldResult e o -> FormFieldResult e o)
-> DSL pq cq cs form m (form Record FormField)
modifyWith f = do
Expand All @@ -120,19 +120,19 @@ component =
case milliseconds of
Nothing -> do
_ <- modifyWith identity
_ <- validate
_ <- validate
eval (SyncFormData a)
Just ms -> do
debounceForm
ms
(modifyWith identity)
(modifyWith (const Validating) *> validate)
debounceForm
ms
(modifyWith identity)
(modifyWith (const Validating) *> validate)
(eval $ SyncFormData a)
pure a

Reset variant a -> do
modifyState_ \st -> st
{ form = Internal.replaceFormFieldInputs (unwrap st.internal).initialInputs st.form
{ form = Internal.unsafeModifyInputVariant identity variant st.form
, internal = over InternalState (_ { allTouched = false }) st.internal
}
eval $ SyncFormData a
Expand Down Expand Up @@ -237,9 +237,9 @@ component =
, form = Internal.replaceFormFieldInputs formInputs st.form
, internal = over
InternalState
(_
(_
{ allTouched = false
, initialInputs = formInputs
, initialInputs = formInputs
}
)
st.internal
Expand Down
12 changes: 6 additions & 6 deletions src/Formless/Query.purs
Original file line number Diff line number Diff line change
Expand Up @@ -288,24 +288,24 @@ reset
:: pq cq cs form inputs m sym a t0 e i o
. IsSymbol sym
=> Initial i
=> Newtype (form Variant InputField) (Variant inputs)
=> Row.Cons sym (InputField e i o) t0 inputs
=> Newtype (form Variant InputFunction) (Variant inputs)
=> Row.Cons sym (InputFunction e i o) t0 inputs
=> SProxy sym
-> a
-> Query pq cq cs form m a
reset sym = Reset (wrap (inj sym (wrap initial)))
reset sym = Reset (wrap (inj sym (wrap (const initial))))

-- | `reset` as an action, so you don't need to specify a `Unit`
-- | result. Use to skip a use of `Halogen.action`.
reset_
:: pq cq cs form inputs m sym t0 e i o
. IsSymbol sym
=> Initial i
=> Newtype (form Variant InputField) (Variant inputs)
=> Row.Cons sym (InputField e i o) t0 inputs
=> Newtype (form Variant InputFunction) (Variant inputs)
=> Row.Cons sym (InputFunction e i o) t0 inputs
=> SProxy sym
-> Query pq cq cs form m Unit
reset_ sym = Reset (wrap (inj sym (wrap initial))) unit
reset_ sym = Reset (wrap (inj sym (wrap (const initial)))) unit

-- | A helper to create the correct `Validate` query for Formless, given
-- | a label
Expand Down
6 changes: 3 additions & 3 deletions src/Formless/Types/Component.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data Query pq cq cs form m a
= Modify (form Variant InputFunction) a
| Validate (form Variant U) a
| ModifyValidate (Maybe Milliseconds) (form Variant InputFunction) a
| Reset (form Variant InputField) a
| Reset (form Variant InputFunction) a
| SetAll (form Record InputField) a
| ModifyAll (form Record InputFunction) a
| ResetAll a
Expand Down Expand Up @@ -92,10 +92,10 @@ newtype InternalState form m = InternalState
}
derive instance newtypeInternalState :: Newtype (InternalState form m) _

-- | A type to represent a running debouncer
-- | A type to represent a running debouncer
type Debouncer =
{ var :: AVar Unit
, fiber :: Fiber Unit
, fiber :: Fiber Unit
}

-- | A type to represent validation status
Expand Down