From 3fd6bd2f7be0b6592929e6827c1351c2f9b06a1a Mon Sep 17 00:00:00 2001 From: Jason Shipman Date: Wed, 24 May 2023 18:04:57 -0400 Subject: [PATCH] Add useSteppingAff hook --- src/React/Basic/Hooks/Aff.purs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/React/Basic/Hooks/Aff.purs b/src/React/Basic/Hooks/Aff.purs index 45e0bed..b05d404 100644 --- a/src/React/Basic/Hooks/Aff.purs +++ b/src/React/Basic/Hooks/Aff.purs @@ -1,5 +1,6 @@ module React.Basic.Hooks.Aff ( useAff + , useSteppingAff , UseAff(..) , useAffReducer , AffReducer @@ -37,11 +38,33 @@ useAff :: deps -> Aff a -> Hook (UseAff deps a) (Maybe a) -useAff deps aff = +useAff = useAff' (const Nothing) + +--| A variant of `useAff` where the asynchronous effect's result is preserved up +--| until the next run of the asynchronous effect _completes_. +--| +--| Contrast this with `useAff`, where the asynchronous effect's result is +--| preserved only up until the next run of the asynchronous effect _starts_. +useSteppingAff :: + forall deps a. + Eq deps => + deps -> + Aff a -> + Hook (UseAff deps a) (Maybe a) +useSteppingAff = useAff' identity + +useAff' :: + forall deps a. + Eq deps => + (Maybe (Either Error a) -> Maybe (Either Error a)) -> + deps -> + Aff a -> + Hook (UseAff deps a) (Maybe a) +useAff' initUpdater deps aff = coerceHook React.do result /\ setResult <- useState Nothing useEffect deps do - setResult (const Nothing) + setResult initUpdater fiber <- launchAff do r <- try aff pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy