@@ -786,17 +786,20 @@ fetch_ loading getData = fetch loading "" (const getData)
786
786
-- | A dummy form that, whenever the specified key changes, performs an
787
787
-- | asynchronous effect. It displays the specified JSX while the effect is not
788
788
-- | complete, sets the form data to the result of the effect and returns it.
789
- asyncEffect :: forall props a . String -> JSX -> Aff a -> FormBuilder props a a
789
+ asyncEffect :: forall props a . String -> JSX -> Aff ( a -> a ) -> FormBuilder props a a
790
790
asyncEffect key loader aff =
791
- withKey key $ formBuilder_ \_ _ onChange ->
792
- keyed key $ asyncWithLoader loader do
793
- newValue <- aff
794
- liftEffect $ onChange newValue
795
- mempty
791
+ withKey key $ formBuilder \_ value ->
792
+ { edit: \onChange ->
793
+ keyed key $ asyncWithLoader loader do
794
+ f <- aff
795
+ liftEffect $ onChange f
796
+ mempty
797
+ , validate: Just value
798
+ }
796
799
797
800
-- | A dummy form that, whenever the specified key changes, performs an
798
801
-- | effect. It sets the form data to the result of the effect and returns it.
799
- effect :: forall props a . String -> Effect a -> FormBuilder props a a
802
+ effect :: forall props a . String -> Effect ( a -> a ) -> FormBuilder props a a
800
803
effect key = asyncEffect key mempty <<< liftEffect
801
804
802
805
-- | Sequential `SeqFormBuilder` used for asynchronously initializing some
@@ -823,16 +826,18 @@ initializer
823
826
:: forall props value
824
827
. Nub (initialized :: Boolean | value ) (initialized :: Boolean | value )
825
828
=> JSX
826
- -> (props -> { | value } -> Aff { | value } )
829
+ -> (props -> { | value } -> Aff ( { initialized :: Boolean | value } -> { initialized :: Boolean | value } ) )
827
830
-> SeqFormBuilder props { initialized :: Boolean | value } Unit
828
831
initializer loader aff =
829
832
sequential " initializer" $ withValue \value@{ initialized } -> withProps \props ->
830
- if initialized
831
- then pure unit
832
- else
833
- invalidate $ void $ asyncEffect " " loader do
834
- newValue <- aff props (contractValue value)
835
- pure $ disjointUnion { initialized: true } newValue
833
+ if initialized then
834
+ pure unit
835
+ else
836
+ invalidate
837
+ $ void
838
+ $ asyncEffect " " loader
839
+ $ map (_{ initialized = true } <<< _)
840
+ $ aff props (contractValue value)
836
841
where
837
842
contractValue :: { initialized :: Boolean | value } -> { | value }
838
843
contractValue = unsafeCoerce
0 commit comments