Skip to content

Commit 5c13e13

Browse files
authored
Remove Promises from PureScript code (#10)
1 parent c6ad7b5 commit 5c13e13

File tree

4 files changed

+13
-36
lines changed

4 files changed

+13
-36
lines changed

bower.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"purescript-numbers": "^6.0.0",
2929
"purescript-prelude": "^4.0.1",
3030
"purescript-profunctor-lenses": "^4.0.0",
31-
"purescript-promises": "^3.0.0",
3231
"purescript-random": "^4.0.0",
3332
"purescript-react-basic": "^8.0.0 || ^9.0.0",
3433
"purescript-react-dnd-basic": "^6.0.0",

docs/Examples/Form.example.purs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ import Data.String as String
1515
import Data.String.NonEmpty (length, NonEmptyString, toString)
1616
import Data.Symbol (SProxy(..))
1717
import Effect (Effect)
18-
import Effect.Aff (Milliseconds(..), delay, error, throwError)
18+
import Effect.Aff (Aff, Milliseconds(..), delay, error, throwError)
1919
import Effect.Class (liftEffect)
20-
import Effect.Promise (Promise)
21-
import Effect.Promise.Unsafe (undefer)
2220
import Effect.Random (randomRange)
2321
import Lumi.Components.Button as Button
2422
import Lumi.Components.Column (column, column_)
23+
import Lumi.Components.Example (example)
2524
import Lumi.Components.Form (FormBuilder, Validated)
2625
import Lumi.Components.Form as F
2726
import Lumi.Components.Form.Defaults (formDefaults)
@@ -33,8 +32,6 @@ import Lumi.Components.Size (Size(..))
3332
import Lumi.Components.Text (h1_)
3433
import Lumi.Components.Upload (FileId(..))
3534
import Lumi.Components.Upload as Upload
36-
import Lumi.Components.Utility.AffToPromise (affToPromise)
37-
import Lumi.Components.Example (example)
3835
import React.Basic (Component, JSX, createComponent, make)
3936
import React.Basic.DOM (css)
4037
import React.Basic.DOM as R
@@ -197,7 +194,7 @@ docs = unit # make component { initialState, render }
197194
}
198195
]
199196

200-
loadColor simulatePauses c = undefer $ affToPromise do
197+
loadColor simulatePauses c = do
201198
when simulatePauses do
202199
delay (Milliseconds 500.0)
203200
case String.toLower c of
@@ -206,7 +203,7 @@ docs = unit # make component { initialState, render }
206203
"blue" -> pure { label: "Blue", value: "blue" }
207204
_ -> throwError (error "No color")
208205

209-
loadColors simulatePauses search = undefer $ affToPromise do
206+
loadColors simulatePauses search = do
210207
when simulatePauses do
211208
delay (Milliseconds 1000.0)
212209
pure
@@ -268,8 +265,8 @@ type ValidatedUser =
268265
userComponent
269266
:: { value :: User
270267
, onChange :: Maybe ValidatedUser -> User -> Effect Unit
271-
, loadColor :: String -> Promise { label :: String, value :: String }
272-
, loadColors :: String -> Promise (Array { label :: String, value :: String })
268+
, loadColor :: String -> Aff { label :: String, value :: String }
269+
, loadColors :: String -> Aff (Array { label :: String, value :: String })
273270
, inlineTable :: Boolean
274271
, forceTopLabels :: Boolean
275272
, readonly :: Boolean

src/Lumi/Components/Form.purs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ import Data.Traversable (intercalate, traverse, traverse_)
6262
import Effect (Effect)
6363
import Effect.Aff (Aff)
6464
import Effect.Class (liftEffect)
65-
import Effect.Promise (Promise)
66-
import Effect.Promise.Unsafe (undefer)
6765
import JSS (JSS, jss)
6866
import Lumi.Components.Color (colors)
6967
import Lumi.Components.Column (column)
@@ -84,7 +82,6 @@ import Lumi.Components.Select as Select
8482
import Lumi.Components.Text (body, body_, subsectionHeader, text)
8583
import Lumi.Components.Textarea as Textarea
8684
import Lumi.Components.Upload as Upload
87-
import Lumi.Components.Utility.AffToPromise (promiseToAff)
8885
import Prim.Row (class Nub, class Union)
8986
import React.Basic (JSX, createComponent, element, empty, fragment, keyed, makeStateless)
9087
import React.Basic.Components.Async (async, asyncWithLoader)
@@ -457,7 +454,7 @@ multiSelect encode opts = formBuilder_ \{ readonly } selected onChange ->
457454
-- | . (Select.SelectOption additionalData -> JSX)
458455
-- | -> FormBuilder
459456
-- | { readonly :: Boolean
460-
-- | , foo :: String -> Promise (Either String
457+
-- | , foo :: String -> Aff (Either String
461458
-- | (Array (Select.SelectOption additionalData)))
462459
-- | | props
463460
-- | }
@@ -468,7 +465,7 @@ asyncSelect
468465
. IsSymbol l
469466
=> Cons
470467
l
471-
(String -> Promise (Array a))
468+
(String -> Aff (Array a))
472469
rest
473470
(readonly :: Boolean | props)
474471
=> SProxy l
@@ -487,7 +484,7 @@ asyncSelect l toSelectOption optionRenderer =
487484

488485
else Select.asyncSingleSelect
489486
{ value
490-
, loadOptions: \search -> promiseToAff (undefer (get l props search))
487+
, loadOptions: get l props
491488
, onChange: onChange
492489
, className: ""
493490
, style: css {}
@@ -510,12 +507,12 @@ asyncSelectByKey
510507
=> IsSymbol l
511508
=> Cons
512509
k
513-
(id -> Promise a)
510+
(id -> Aff a)
514511
rest1
515512
(readonly :: Boolean | props)
516513
=> Cons
517514
l
518-
(String -> Promise (Array a))
515+
(String -> Aff (Array a))
519516
rest2
520517
(readonly :: Boolean | props)
521518
=> SProxy k
@@ -528,7 +525,7 @@ asyncSelectByKey
528525
asyncSelectByKey k l fromId toId toSelectOption optionRenderer =
529526
formBuilder_ \props@{ readonly } value onChange ->
530527
FetchCache.single
531-
{ getData: \key -> promiseToAff (undefer (get k props (toId key)))
528+
{ getData: \key -> get k props (toId key)
532529
, id: map fromId value
533530
, render: \data_ ->
534531
if readonly
@@ -546,7 +543,7 @@ asyncSelectByKey k l fromId toId toSelectOption optionRenderer =
546543
else
547544
Select.asyncSingleSelect
548545
{ value: data_
549-
, loadOptions: \search -> promiseToAff (undefer (get l props search))
546+
, loadOptions: get l props
550547
, onChange: onChange <<< map (toId <<< _.value <<< toSelectOption)
551548
, className: ""
552549
, style: css {}

src/Lumi/Components/Utility/AffToPromise.purs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)