Skip to content

Commit 9373124

Browse files
Rintcius Bloksharkdp
Rintcius Blok
authored andcommitted
Add flareWith (#19)
Added a flareWith function which enables hooking Flares without running the signal. It is just a slightly more generic version of runFlareWith (and is now written in terms of flareWith).
1 parent 1e79541 commit 9373124

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Flare.purs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module Flare
4343
, liftSF
4444
, foldp
4545
, setupFlare
46+
, flareWith
4647
, runFlareWith
4748
, runFlare
4849
, runFlareShow
@@ -385,18 +386,27 @@ setupFlare (UI setupUI) = do
385386
(Flare components signal) <- setupUI
386387
pure { components, signal }
387388

389+
-- | Renders a Flare UI to the DOM and sets up all event handlers. The ID
390+
-- | specifies the HTML element to which the controls are attached. The
391+
-- | handler function argument handles the `Signal` inside the `Flare`.
392+
flareWith :: forall e a. ElementId
393+
-> (S.Signal a -> Eff (dom :: DOM, channel :: CHANNEL | e) Unit)
394+
-> UI e a
395+
-> Eff (dom :: DOM, channel :: CHANNEL | e) Unit
396+
flareWith controls handler (UI setupUI) = do
397+
(Flare components signal) <- setupUI
398+
removeChildren controls
399+
traverse_ (appendComponent controls) components
400+
handler signal
401+
388402
-- | Renders a Flare UI to the DOM and sets up all event handlers. The ID
389403
-- | specifies the HTML element to which the controls are attached. The
390404
-- | function argument will be mapped over the `Signal` inside the `Flare`.
391405
runFlareWith :: forall e a. ElementId
392406
-> (a -> Eff (dom :: DOM, channel :: CHANNEL | e) Unit)
393407
-> UI e a
394408
-> Eff (dom :: DOM, channel :: CHANNEL | e) Unit
395-
runFlareWith controls handler (UI setupUI) = do
396-
(Flare components signal) <- setupUI
397-
removeChildren controls
398-
traverse_ (appendComponent controls) components
399-
S.runSignal (map handler signal)
409+
runFlareWith controls handler ui = flareWith controls (S.runSignal <<< map handler) ui
400410

401411
-- | Renders a Flare UI to the DOM and sets up all event handlers. The two IDs
402412
-- | specify the DOM elements to which the controls and the output will be

0 commit comments

Comments
 (0)