Skip to content

Commit 78be20c

Browse files
committed
fix inputs sync
1 parent f20236a commit 78be20c

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

ghcjs/delivery-calculator/src/Main.hs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import qualified Functora.Money as Money
2626
import qualified Functora.Prelude as Prelude
2727
import qualified Functora.Rates as Rates
2828
import qualified Functora.Web as Web
29-
import Language.Javascript.JSaddle ((!), (!!))
29+
import Language.Javascript.JSaddle ((!))
3030
import qualified Language.Javascript.JSaddle as JS
3131
import qualified Miso
3232
import qualified Network.URI as URI (parseURI)
@@ -356,13 +356,12 @@ viewModel st =
356356
-- https://github.com/dmjio/miso/issues/272
357357
--
358358
syncInputs :: Model -> JSM ()
359-
syncInputs st =
360-
void
361-
. Syb.everywhereM (Syb.mkM fun)
362-
$ modelState st
359+
syncInputs st = do
360+
act <- JS.global ! ("document" :: Unicode) ! ("activeElement" :: Unicode)
361+
void . Syb.everywhereM (Syb.mkM $ fun act) $ modelState st
363362
where
364-
fun :: Unique Unicode -> JSM (Unique Unicode)
365-
fun txt = do
363+
fun :: JS.JSVal -> Unique Unicode -> JSM (Unique Unicode)
364+
fun act txt = do
366365
el <-
367366
getElementById
368367
. either impureThrow id
@@ -373,17 +372,7 @@ syncInputs st =
373372
^. #uniqueUid
374373
elExist <- ghcjsPure $ JS.isTruthy el
375374
when elExist $ do
376-
inps <-
377-
el
378-
^. JS.js1
379-
("getElementsByTagName" :: Unicode)
380-
("input" :: Unicode)
381-
inp <- inps !! 0
382-
act <-
383-
JS.global
384-
! ("document" :: Unicode)
385-
! ("activeElement" :: Unicode)
386-
elActive <- JS.strictEqual inp act
375+
elActive <- JS.strictEqual el act
387376
unless elActive $ el ^. JS.jss ("value" :: Unicode) (txt ^. #uniqueValue)
388377
pure txt
389378

ghcjs/miso-functora/src/Functora/Miso/Types.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ data Fav = Fav
435435
deriving stock (Eq, Ord, Show, Data, Generic)
436436
deriving (ToJSON, FromJSON) via GenericType Fav
437437

438+
--
439+
-- TODO : probably don't need debounce in most cases,
440+
-- maybe just eliminate this wrapper type for reduncancy.
441+
--
438442
data InstantOrDelayed a
439443
= Instant a
440444
| Delayed Natural a

ghcjs/miso-functora/src/Functora/Miso/Widgets/Field.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ field Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts =
157157
[ fmap
158158
(type_ . htmlFieldType)
159159
(st ^? cloneTraversal optic . #fieldType),
160+
fmap
161+
(textProp "defaultValue")
162+
(st ^? cloneTraversal optic . #fieldInput . #uniqueValue),
160163
Just $ onInput onInputAction,
161164
Just . disabled_ $ opts ^. #optsDisabled,
162165
fmap placeholder_

0 commit comments

Comments
 (0)