From 4de3076750b14a798ac172239bbc02647fccf882 Mon Sep 17 00:00:00 2001 From: Brandon Elam Barker Date: Sun, 16 May 2021 18:06:15 -0400 Subject: [PATCH] adding ajbarber's patch to concur and associated debounce (#129) --- packages.dhall | 10 ++++++---- src/Metajelo/FormUtil.purs | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/packages.dhall b/packages.dhall index ca1d7aa..c132023 100644 --- a/packages.dhall +++ b/packages.dhall @@ -139,14 +139,16 @@ let additions = , "arrays" , "avar" , "console" + , "debug" , "foldable-traversable" , "free" + , "js-timers" , "nonempty" , "profunctor-lenses" , "tailrec" ] - "https://github.com/purescript-concur/purescript-concur-core.git" - "f175dd4a4f7b8904d2cc4abb51e3b5179140c294" + "https://github.com/ajbarber/purescript-concur-core.git" + "c66c3a9f8e7e325e86ab5faa1505aa2e51a46e4b" , concur-react = mkPackage [ "aff" @@ -162,8 +164,8 @@ let additions = , "web-dom" , "web-html" ] - "https://github.com/purescript-concur/purescript-concur-react.git" - "v0.4.2" + "https://github.com/ajbarber/purescript-concur-react.git" + "ed06698d06582cc0d64bd2d7c667b0a8964b447b" , datacite = { dependencies = [ "effect", "functors", "generics-rep", "naturals", "simple-json" ] diff --git a/src/Metajelo/FormUtil.purs b/src/Metajelo/FormUtil.purs index a9fe37b..a273cd5 100644 --- a/src/Metajelo/FormUtil.purs +++ b/src/Metajelo/FormUtil.purs @@ -2,7 +2,8 @@ module Metajelo.FormUtil where import Concur.Core (Widget) import Concur.Core.ElementBuilder (Element) -import Concur.Core.FRP (Signal, debounce, display, fireOnce, justWait, loopS, loopW, oneShot, step) +import Concur.Core.FRP (Signal, display, fireOnce, justWait, loopS, loopW, oneShot, step) +import Concur.Core.Types (debounced) import Concur.React (HTML) import Concur.React.DOM as D import Concur.React.Props as P @@ -11,16 +12,16 @@ import Control.Alternative (empty) import Control.Applicative (class Applicative) import Control.Apply (class Apply, apply) import Control.Extend (class Extend) -import Data.Array as A import Data.Array (catMaybes, filter, length, replicate, (:), (..)) +import Data.Array as A import Data.Array.NonEmpty (NonEmptyArray, fromArray, toArray) import Data.Bifunctor (lmap) import Data.Bounded (bottom) -import Data.Eq ((==)) import Data.Date (canonicalDate) import Data.DateTime (DateTime(..)) import Data.Either (Either(..), hush) import Data.Enum (class BoundedEnum, class Enum, class SmallBounded, upFromIncluding, toEnum) +import Data.Eq ((==)) import Data.Foldable (class Foldable, fold) import Data.Functor (class Functor) import Data.Generic.Rep (class Generic) @@ -72,11 +73,11 @@ import Web.DOM (Node) import Web.DOM.Document (Document, getElementsByClassName, toNonElementParentNode) import Web.DOM.Element as Ele import Web.DOM.HTMLCollection as HTML -import Web.HTML.HTMLDocument as HTML -import Web.HTML.HTMLInputElement as HTML import Web.DOM.NonElementParentNode (getElementById) import Web.DOM.ParentNode (children) import Web.HTML (window) +import Web.HTML.HTMLDocument as HTML +import Web.HTML.HTMLInputElement as HTML import Web.HTML.Window (document) type Email = EA.EmailAddress @@ -146,18 +147,18 @@ labelSig widg props sigIn = D.div_ props do sigIn textInputWidget :: String -> Widget HTML String -textInputWidget txt = +textInputWidget txt = debounced 1000 $ D.input [P.defaultValue txt, P.unsafeTargetValue <$> P.onChange] textInput' :: CtrlSignal HTML String -textInput' initVal = sig initVal +textInput' initVal = sigNow initVal where -- Alternative to 'sig' that doesn't debounce, for debugging: - -- sigNow rs = step rs $ do - -- pure $ unsafePerformEffect $ log $ "refstr in textInput sigNow': " <> (show rs) - -- rsNew <- textInputWidget rs - -- pure $ sigNow rsNew - sig txt = debounce 1000.0 txt textInputWidget + sigNow rs = step rs $ do + pure $ unsafePerformEffect $ log $ "refstr in textInput sigNow': " <> (show rs) + rsNew <- textInputWidget rs + pure $ sigNow rsNew + --sig txt = debounce 1000.0 txt textInputWidget -- | Reasonable defaults for filtering input text textFilter :: Signal HTML String -> Signal HTML (Maybe NonEmptyString)