@@ -17,7 +17,7 @@ import Data.String as String
1717import Data.String.NonEmpty (NonEmptyString , appendString , length , toString )
1818import Data.Symbol (SProxy (..))
1919import Effect (Effect )
20- import Effect.Aff (Aff , Milliseconds (..), delay , error , throwError )
20+ import Effect.Aff (Milliseconds (..), delay , error , throwError )
2121import Effect.Class (liftEffect )
2222import Effect.Random (randomRange )
2323import Lumi.Components.Button as Button
@@ -85,9 +85,8 @@ docs = unit # make component { initialState, render }
8585 SetUser update ->
8686 let
8787 formProps =
88- { loadColor: loadColor self.state.simulatePauses
89- , loadColors: loadColors self.state.simulatePauses
90- , readonly: self.state.readonly
88+ { readonly: self.state.readonly
89+ , simulatePauses: self.state.simulatePauses
9190 }
9291 in
9392 self.setState \s -> s
@@ -166,11 +165,10 @@ docs = unit # make component { initialState, render }
166165 [ userComponent
167166 { value: user
168167 , onChange: send self <<< SetUser
169- , loadColor: loadColor simulatePauses
170- , loadColors: loadColors simulatePauses
171168 , inlineTable
172169 , forceTopLabels: forceTopLabels && not inlineTable
173170 , readonly
171+ , simulatePauses
174172 }
175173 , row
176174 { style: css { justifyContent: " flex-end" }
@@ -204,30 +202,6 @@ docs = unit # make component { initialState, render }
204202 }
205203 ]
206204
207- loadColor simulatePauses c = do
208- when simulatePauses do
209- delay (Milliseconds 500.0 )
210- case String .toLower c of
211- " red" -> pure { label: " Red" , value: " red" }
212- " green" -> pure { label: " Green" , value: " green" }
213- " blue" -> pure { label: " Blue" , value: " blue" }
214- " brown" -> pure { label: " Brown" , value: " brown" }
215- " black" -> pure { label: " Black" , value: " black" }
216- " white" -> pure { label: " White" , value: " white" }
217- _ -> throwError (error " No color" )
218-
219- loadColors simulatePauses search = do
220- when simulatePauses do
221- delay (Milliseconds 1000.0 )
222- pure
223- [ { label: " Red" , value: " red" }
224- , { label: " Green" , value: " green" }
225- , { label: " Blue" , value: " blue" }
226- , { label: " Brown" , value: " brown" }
227- , { label: " Black" , value: " black" }
228- , { label: " White" , value: " white" }
229- ]
230-
231205data Country
232206 = BR
233207 | US
@@ -297,21 +271,19 @@ type ValidatedPet =
297271userComponent
298272 :: { value :: User
299273 , onChange :: (User -> User ) -> Effect Unit
300- , loadColor :: String -> Aff { label :: String , value :: String }
301- , loadColors :: String -> Aff (Array { label :: String , value :: String } )
302274 , inlineTable :: Boolean
303275 , forceTopLabels :: Boolean
304276 , readonly :: Boolean
277+ , simulatePauses :: Boolean
305278 }
306279 -> JSX
307280userComponent = F .build userForm
308281
309282userForm
310283 :: forall props
311284 . FormBuilder
312- { loadColor :: String -> Aff { label :: String , value :: String }
313- , loadColors :: String -> Aff (Array { label :: String , value :: String } )
314- , readonly :: Boolean
285+ { readonly :: Boolean
286+ , simulatePauses :: Boolean
315287 | props
316288 }
317289 User
@@ -448,14 +420,15 @@ userForm = ado
448420 }
449421 color <-
450422 FT .column_ " Color"
451- $ F .focus (prop (SProxy :: SProxy " color" ))
452- $ F .asyncSelectByKey
453- (SProxy :: SProxy " loadColor" )
454- (SProxy :: SProxy " loadColors" )
455- identity
456- identity
457- identity
458- (R .text <<< _.label)
423+ $ F .withProps \props ->
424+ F .focus (prop (SProxy :: SProxy " color" ))
425+ $ F .asyncSelectByKey
426+ (loadColor props.simulatePauses)
427+ (loadColors props.simulatePauses)
428+ identity
429+ identity
430+ identity
431+ (R .text <<< _.label)
459432 in
460433 { name
461434 , animal
@@ -507,6 +480,26 @@ userForm = ado
507480 interval <- liftEffect $ randomRange 100.0 700.0
508481 delay $ Milliseconds interval
509482
483+ loadColor simulatePauses c = do
484+ when simulatePauses do
485+ randomPause
486+ case String .toLower c of
487+ " red" -> pure { label: " Red" , value: " red" }
488+ " green" -> pure { label: " Green" , value: " green" }
489+ " blue" -> pure { label: " Blue" , value: " blue" }
490+ _ -> throwError (error " No color" )
491+
492+ loadColors simulatePauses search = do
493+ when simulatePauses do
494+ randomPause
495+ randomPause
496+ pure
497+ [ { label: " Red" , value: " red" }
498+ , { label: " Green" , value: " green" }
499+ , { label: " Blue" , value: " blue" }
500+ ]
501+
502+
510503type Address =
511504 { name :: Validated String
512505 , street :: Validated String
0 commit comments