@@ -23,8 +23,6 @@ module Yoga.React.Om
24 , useTransition
24 , useTransition
25 , useDeferredValue
25 , useDeferredValue
28 , module ReExports
26 , module ReExports
@@ -37,12 +35,8 @@ import Control.Bind.Indexed (class IxBind, ibind)
37import Control.Monad.Indexed (class IxMonad)
35import Control.Monad.Indexed (class IxMonad)
38import Data.Functor.Indexed (class IxFunctor)
36import Data.Functor.Indexed (class IxFunctor)
39import Data.Newtype (class Newtype, un)
37import Data.Newtype (class Newtype, un)
40−import Data.Either (Either(..))
41−import Data.Maybe (Maybe(..))
42import Data.Tuple.Nested ((/\), type (/\))
38import Data.Tuple.Nested ((/\), type (/\))
43import Effect (Effect)
39import Effect (Effect)
44−import Effect.Aff (error, killFiber, launchAff, launchAff_, try)
45−import Effect.Aff as Aff
46import Effect.Class (liftEffect)
40import Effect.Class (liftEffect)
47import Effect.Ref as Ref
41import Effect.Ref as Ref
48import Effect.Unsafe (unsafePerformEffect)
42import Effect.Unsafe (unsafePerformEffect)
@@ -226,30 +220,6 @@ useDeferredValue
226 -> OmRender ctx hooks (Hooks.UseDeferredValue a hooks) a
220 -> OmRender ctx hooks (Hooks.UseDeferredValue a hooks) a
227useDeferredValue a = liftRender (Hooks.useDeferredValue a)
221useDeferredValue a = liftRender (Hooks.useDeferredValue a)
229−data UseAff :: Type -> Type -> Type -> Type
230−data UseAff deps a hooks
233− :: forall ctx deps a hooks
236− -> Om { | ctx } () a
237− -> OmRender ctx hooks (UseAff deps a hooks) (Maybe a)
238−useAff deps om = fromEffect Prelude.do
239− ctx <- toEffect (useOm @ctx Prelude.pure)
240− result /\ setResult <- toEffect (useState Nothing)
241− toEffect $ useEffect deps Prelude.do
242− setResult (const Nothing)
243− fiber <- launchAff Prelude.do
244− r <- try (Om.runOm ctx { exception: \e -> Aff.throwError e } om)
245− liftEffect (setResult \_ -> Just r)
246− Prelude.pure Prelude.do
247− launchAff_ (killFiber (error "Stale request cancelled") fiber)
248− toEffect $ liftRender $ unsafeRenderEffect case result of
249− Just (Left err) -> Aff.throwError err
250− Just (Right a) -> Prelude.pure (Just a)
251− Nothing -> Prelude.pure Nothing
253omComponent
223omComponent
254 :: forall @ctx @err hooks props
224 :: forall @ctx @err hooks props