Skip to content

Commit 9ec5ebf

Browse files
koterpillarsharkdp
authored andcommitted
Add Signal.get to simplify the innerFlare type
1 parent 0856e40 commit 9ec5ebf

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

html/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ <h3>Example 14: Color picker (running Flare inside Flare)</h3>
175175
<*> is "Green" 0
176176
<*> is "Blue" 100
177177

178-
ui = traverse_ toHTML <$>
178+
ui = toHTML <$>
179179
select "Color domain" (HSL :| [RGB]) showDomain `innerFlare` uiColor
180180
</pre>
181181
<div id="controls14"></div>

src/Flare.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ exports.createInnerElementP = function(tuple) {
3535
};
3636
};
3737

38+
exports.get = function (sig) {
39+
return function () {
40+
return sig.get();
41+
};
42+
};
43+
3844
exports.appendComponent = function(target) {
3945
return function(el) {
4046
return function() {

src/Flare.purs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,19 +449,24 @@ flareWith controls handler (UI setupUI) = do
449449
-- | Renders an UI with access to the current value.
450450
innerFlare :: forall e a b. UI e a
451451
-> (a -> UI e b)
452-
-> UI e (Maybe b)
452+
-> UI e b
453453
innerFlare (UI setupUI) innerUI = UI $ do
454454
(Flare components signal) <- setupUI
455+
-- Get the initial value for the resulting signal
456+
UI setupInnerUI <- innerUI <$> get signal
457+
(Flare _ innerSignal) <- setupInnerUI
458+
initialInner <- get innerSignal
459+
innerResult <- channel initialInner
460+
-- Set up the inner UI
455461
Tuple innerHostId innerHost <- createInnerElement
456-
-- FIXME: there's no way to create a channel without a value, and no way to
457-
-- get the current value out of signal, thus Maybe in the type
458-
--
459-
-- innerResult <- channel $ innerUI $ get signal
460-
innerResult <- channel Nothing
461-
let setupInner = innerUI >>> flareWith innerHostId (map (Just >>> send innerResult) >>> S.runSignal)
462+
let setupInner = innerUI >>> flareWith innerHostId (map (send innerResult) >>> S.runSignal)
462463
S.runSignal $ setupInner <$> signal
463464
pure $ Flare (components <> [innerHost]) (subscribe innerResult)
464465

466+
-- | Get the current value of a signal. Should be in purescript-signal, pending
467+
-- https://github.com/bodil/purescript-signal/pull/60
468+
foreign import get :: forall e a. S.Signal a -> Eff e a
469+
465470
-- | Renders a Flare UI to the DOM and sets up all event handlers. The ID
466471
-- | specifies the HTML element to which the controls are attached. The
467472
-- | function argument will be mapped over the `Signal` inside the `Flare`.

test/Main.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ uiColor RGB = rgb <$> is "Red" 200
181181
<*> is "Blue" 100
182182

183183
ui14 :: forall e m. UI e (H.Markup m)
184-
ui14 = traverse_ toHTML <$>
184+
ui14 = toHTML <$>
185185
select "Color domain" (HSL :| [RGB]) showDomain `innerFlare` uiColor
186186

187187
-- Example 15

0 commit comments

Comments
 (0)