Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-reactix
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-reactix
Commits
17be13a4
Commit
17be13a4
authored
Apr 25, 2019
by
James Laver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed Refs api
parent
c2cd0e75
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
12 deletions
+20
-12
Hooks.purs
src/Reactix/Hooks.purs
+14
-5
Spec.purs
test/Reactix/React/Spec.purs
+6
-7
No files found.
src/Reactix/Hooks.purs
View file @
17be13a4
...
@@ -8,7 +8,7 @@ module Reactix.Hooks
...
@@ -8,7 +8,7 @@ module Reactix.Hooks
-- , useReducer, useReducer'
-- , useReducer, useReducer'
-- , useContext
-- , useContext
-- , useMemo, useMemo1, useMemo2 --, useMemo3, useMemo4, useMemo5
-- , useMemo, useMemo1, useMemo2 --, useMemo3, useMemo4, useMemo5
, Ref, useRef
, Ref, useRef
, readRef, setRef
-- , useDebugValue, useDebugValue'
-- , useDebugValue, useDebugValue'
-- , useImperativeHandle
-- , useImperativeHandle
)
)
...
@@ -19,7 +19,7 @@ import Data.Function.Uncurried ( Fn2, mkFn2, runFn2 )
...
@@ -19,7 +19,7 @@ import Data.Function.Uncurried ( Fn2, mkFn2, runFn2 )
import Data.Tuple ( Tuple(..) )
import Data.Tuple ( Tuple(..) )
import Effect ( Effect )
import Effect ( Effect )
import Effect.Uncurried ( EffectFn1, runEffectFn1, EffectFn2, runEffectFn2, EffectFn3, runEffectFn3, EffectFn4, runEffectFn4, EffectFn5, runEffectFn5, EffectFn6, runEffectFn6 )
import Effect.Uncurried ( EffectFn1, runEffectFn1, EffectFn2, runEffectFn2, EffectFn3, runEffectFn3, EffectFn4, runEffectFn4, EffectFn5, runEffectFn5, EffectFn6, runEffectFn6 )
import FFI.Simple ( (...),
delay, args2, args3, args4, args5
)
import FFI.Simple ( (...),
(..), delay, args2, args3, args4, args5, setProperty
)
import DOM.Simple.Console
import DOM.Simple.Console
import Reactix.React ( Hooks, react, unsafeHooksEffect )
import Reactix.React ( Hooks, react, unsafeHooksEffect )
...
@@ -34,7 +34,7 @@ type State state = Tuple state (state -> Effect Unit)
...
@@ -34,7 +34,7 @@ type State state = Tuple state (state -> Effect Unit)
-- | Given an Effect function returning an initial value, returns a State
-- | Given an Effect function returning an initial value, returns a State
useState :: forall s. (Unit -> Effect s) -> Hooks (State s)
useState :: forall s. (Unit -> Effect s) -> Hooks (State s)
useState s = hook $ \_ -> pure $ currySecond $ react ... "useState" $ [ delay s ]
useState s = hook $ \_ -> pure $ currySecond $
tuple $
react ... "useState" $ [ delay s ]
-- -- useReducer
-- -- useReducer
-- type Reducer state action = Tuple state (EffectFn1 action Unit)
-- type Reducer state action = Tuple state (EffectFn1 action Unit)
...
@@ -142,10 +142,19 @@ useLayoutEffect5 a b c d f e = _useLayoutEffect e $ args5 a b c d f
...
@@ -142,10 +142,19 @@ useLayoutEffect5 a b c d f e = _useLayoutEffect e $ args5 a b c d f
-- useRef
-- useRef
type Ref state = Tuple state (state -> Effect Unit)
foreign import data Ref :: Type -> Type
useRef :: forall r. r -> Hooks (Ref r)
useRef :: forall r. r -> Hooks (Ref r)
useRef r = hook $ \_ -> pure $ currySecond $ tupleCurrent $ react ... "useRef" $ [ r ]
useRef r = hook $ \_ -> pure $ react ... "useRef" $ [ r ]
readRef :: forall r. Ref r -> r
readRef r = r .. "current"
setRef :: forall r. Ref r -> r -> Effect Unit
setRef r v = delay $ \_ -> do
_ <- pure $ setProperty "current" r v
pure unit
-- useContext
-- useContext
...
...
test/Reactix/React/Spec.purs
View file @
17be13a4
...
@@ -23,8 +23,7 @@ import DOM.Simple.Event as Event
...
@@ -23,8 +23,7 @@ import DOM.Simple.Event as Event
import Reactix as R
import Reactix as R
import Reactix.Test as RT
import Reactix.Test as RT
import Reactix.DOM.Raw ( button, div, i, text )
import Reactix.DOM.Raw ( button, div, i, text )
import Reactix.Hooks ( useState, useEffect, useLayoutEffect )
import DOM.Simple.Console
staticTest :: Spec Unit
staticTest :: Spec Unit
staticTest =
staticTest =
describe "Basic DOM rendering" $ do
describe "Basic DOM rendering" $ do
...
@@ -49,9 +48,9 @@ counterCpt :: R.Component CounterProps
...
@@ -49,9 +48,9 @@ counterCpt :: R.Component CounterProps
counterCpt = R.hooksComponent "Counter" cpt
counterCpt = R.hooksComponent "Counter" cpt
where
where
cpt {count} _ = do
cpt {count} _ = do
y /\ setY <- useState $ \_ -> pure count
y /\ setY <-
R.
useState $ \_ -> pure count
pure $ div { className: "counter" }
pure $ div { className: "counter" }
[ button { type: "button", onClick: onclick setY (y + 1) } [ text "++" ]
[ button { type: "button",
onClick: onclick setY (y + 1) } [ text "++" ]
, div {} [ text (show y) ] ]
, div {} [ text (show y) ] ]
onclick set to = mkEffectFn1 $ \e -> set to
onclick set to = mkEffectFn1 $ \e -> set to
...
@@ -98,7 +97,7 @@ type EffectorProps = ( stateRef :: Ref.Ref EffectorState )
...
@@ -98,7 +97,7 @@ type EffectorProps = ( stateRef :: Ref.Ref EffectorState )
effectorCpt :: R.Component EffectorProps
effectorCpt :: R.Component EffectorProps
effectorCpt = R.hooksComponent "Effector" cpt
effectorCpt = R.hooksComponent "Effector" cpt
where cpt {stateRef} _ = do
where cpt {stateRef} _ = do
useEffect $ \_ -> do
R.
useEffect $ \_ -> do
Ref.write Initialised stateRef
Ref.write Initialised stateRef
pure $ \_ -> Ref.write Done stateRef
pure $ \_ -> Ref.write Done stateRef
pure $ div {} []
pure $ div {} []
...
@@ -126,7 +125,7 @@ effectorTest =
...
@@ -126,7 +125,7 @@ effectorTest =
layoutEffectorCpt :: R.Component EffectorProps
layoutEffectorCpt :: R.Component EffectorProps
layoutEffectorCpt = R.hooksComponent "LayoutEffector" cpt
layoutEffectorCpt = R.hooksComponent "LayoutEffector" cpt
where cpt {stateRef} _ = do
where cpt {stateRef} _ = do
useLayoutEffect $ \_ -> do
R.
useLayoutEffect $ \_ -> do
Ref.write Initialised stateRef
Ref.write Initialised stateRef
pure $ \_ -> Ref.write Done stateRef
pure $ \_ -> Ref.write Done stateRef
pure $ div {} []
pure $ div {} []
...
@@ -156,7 +155,7 @@ type ContextProps = ()
...
@@ -156,7 +155,7 @@ type ContextProps = ()
-- contextualCpt :: R.Component ContextProps
-- contextualCpt :: R.Component ContextProps
-- contextualCpt = R.hooksComponent "Contextual" cpt
-- contextualCpt = R.hooksComponent "Contextual" cpt
-- where cpt {stateRef} _ = do
-- where cpt {stateRef} _ = do
-- useEffect $ \_ -> do
--
R.
useEffect $ \_ -> do
-- Ref.write Initialised stateRef
-- Ref.write Initialised stateRef
-- pure $ \_ -> Ref.write Done stateRef
-- pure $ \_ -> Ref.write Done stateRef
-- pure $ div {} []
-- pure $ div {} []
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment