@@ -43,6 +43,8 @@ module React.Basic.Hooks
4343 , toKey
4444 , unsafeToKey
4545 , Render
46+ , Pure
47+ , Hook
4648 , bind
4749 , discard
4850 , pure
@@ -96,38 +98,36 @@ memo = flip Prelude.bind (runEffectFn1 memo_)
9698foreign import data UseState :: Type -> Type -> Type
9799
98100useState
99- :: forall hooks state
101+ :: forall state
100102 . state
101- -> Render hooks (UseState state hooks ) (Tuple state ((state -> state ) -> Effect Unit ))
103+ -> Hook (UseState state ) (Tuple state ((state -> state ) -> Effect Unit ))
102104useState initialState = Render do
103105 runEffectFn2 useState_ (mkFn2 Tuple ) initialState
104106
105107foreign import data UseEffect :: Type -> Type
106108
107109useEffect
108- :: forall hooks
109- . Array Key
110+ :: Array Key
110111 -> Effect (Effect Unit )
111- -> Render hooks ( UseEffect hooks ) Unit
112+ -> Hook UseEffect Unit
112113useEffect keys effect = Render (runEffectFn2 useEffect_ effect keys)
113114
114115foreign import data UseLayoutEffect :: Type -> Type
115116
116117useLayoutEffect
117- :: forall hooks
118- . Array Key
118+ :: Array Key
119119 -> Effect (Effect Unit )
120- -> Render hooks ( UseLayoutEffect hooks ) Unit
120+ -> Hook UseLayoutEffect Unit
121121useLayoutEffect keys effect = Render (runEffectFn2 useLayoutEffect_ effect keys)
122122
123123foreign import data UseReducer :: Type -> Type -> Type -> Type
124124
125125useReducer
126- :: forall hooks state action
126+ :: forall state action
127127 . ToKey state
128128 => state
129129 -> (state -> action -> state )
130- -> Render hooks (UseReducer state action hooks ) (Tuple state (action -> Effect Unit ))
130+ -> Hook (UseReducer state action ) (Tuple state (action -> Effect Unit ))
131131useReducer initialState reducer = Render do
132132 runEffectFn3 useReducer_
133133 (mkFn2 Tuple )
@@ -138,10 +138,7 @@ foreign import data UseRef :: Type -> Type -> Type
138138
139139foreign import data Ref :: Type -> Type
140140
141- useRef
142- :: forall hooks a
143- . a
144- -> Render hooks (UseRef a hooks ) (Ref a )
141+ useRef :: forall a . a -> Hook (UseRef a ) (Ref a )
145142useRef initialValue = Render do
146143 runEffectFn1 useRef_ initialValue
147144
@@ -154,20 +151,17 @@ readRefMaybe a = map toMaybe (readRef a)
154151writeRef :: forall a . Ref a -> a -> Effect Unit
155152writeRef = runEffectFn2 writeRef_
156153
157- renderRef :: forall hooks a . Ref a -> Render hooks hooks a
154+ renderRef :: forall a . Ref a -> Pure a
158155renderRef ref = Render (readRef ref)
159156
160- renderRefMaybe :: forall hooks a . Ref (Nullable a ) -> Render hooks hooks (Maybe a )
157+ renderRefMaybe :: forall a . Ref (Nullable a ) -> Pure (Maybe a )
161158renderRefMaybe a = Render (readRefMaybe a)
162159
163160foreign import data UseContext :: Type -> Type -> Type
164161
165162foreign import data Context :: Type -> Type
166163
167- useContext
168- :: forall hooks a
169- . Context a
170- -> Render hooks (UseContext a hooks ) (Maybe a )
164+ useContext :: forall a . Context a -> Hook (UseContext a ) (Maybe a )
171165useContext context = Render (map toMaybe (runEffectFn1 useContext_ context))
172166
173167createContext :: forall a . a -> Effect (Context a )
@@ -178,11 +172,7 @@ contextProvider context a child = element (contextProvider_ context) { value: a,
178172
179173foreign import data UseMemo :: Type -> Type -> Type
180174
181- useMemo
182- :: forall hooks a
183- . Array Key
184- -> (Unit -> a )
185- -> Render hooks (UseMemo a hooks ) a
175+ useMemo :: forall a . Array Key -> (Unit -> a ) -> Hook (UseMemo a ) a
186176useMemo keys factory = Render (runEffectFn2 useMemo_ factory keys)
187177
188178-- | Keys represent values React uses to check for changes.
@@ -230,6 +220,10 @@ instance trMaybe :: ToKey (Maybe a) where
230220-- | effects.
231221newtype Render x y a = Render (Effect a )
232222
223+ type Pure a = forall hooks . Render hooks hooks a
224+
225+ type Hook (newHook :: Type -> Type ) a = forall hooks . Render hooks (newHook hooks ) a
226+
233227instance ixFunctorRender :: IxFunctor Render where
234228 imap f (Render a) = Render (map f a)
235229
0 commit comments