-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
61 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
let upstream = | ||
https://raw.githubusercontent.com/purescript/package-sets/psc-0.15.13-20231201/src/packages.dhall | ||
sha256:706a855400108a03b35bd37afe7f50802deed882c555171d266338d4694ddbe8 | ||
https://raw.githubusercontent.com/purescript/package-sets/psc-0.15.15-20240711/src/packages.dhall | ||
sha256:81881d9e15484551b4293ab0a2639355f38d0cab1dfa49a077b5f1af374c292a | ||
|
||
in upstream | ||
with elmish.version = "v0.11.1" | ||
with elmish-html.version = "v0.8.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Elmish.Hooks.UseSubscription | ||
( UseSubscription | ||
, useSubscription | ||
) where | ||
|
||
import Prelude | ||
|
||
import Effect.Aff (Aff) | ||
import Elmish.Component (ComponentName(..)) | ||
import Elmish.Hooks.Type (Hook, HookType, mkHook) | ||
import Elmish.Subscription (Subscription) | ||
import Elmish.Subscription as Sub | ||
|
||
foreign import data UseSubscription :: Type -> HookType | ||
|
||
-- | Subscribes to the given subscription and calls the provided callback every | ||
-- | time the subscription yields a value. | ||
-- | | ||
-- | ```purs | ||
-- | listenToNetwork :: Subscription Aff NetworkSignal | ||
-- | listenToNetwork = ... | ||
-- | | ||
-- | view :: ReactElement | ||
-- | view = Hooks.component Hooks.do | ||
-- | lastSignal /\ setLastSignal <- Hooks.useState Nothing | ||
-- | useSubscription listenToNetwork \signal -> setLastSignal (Just signal) | ||
-- | Hooks.pure $ | ||
-- | case lastSignal of | ||
-- | Nothing -> H.div "bg-secondary" "Waiting for signal..." | ||
-- | Just signal -> H.div "bg-success" $ "Received signal: " <> show signal | ||
-- | ``` | ||
useSubscription :: ∀ a. Subscription Aff a -> (a -> Aff Unit) -> Hook (UseSubscription a) Unit | ||
useSubscription subscription onValue = | ||
mkHook (ComponentName "UseSubscription") \render -> | ||
{ init: subscription # Sub.quasiBind onValue # Sub.subscribe identity | ||
, update: \_ _ -> pure unit | ||
, view: \_ _ -> render unit | ||
} |