Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated to purescript 0.10.4 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"license": "MIT",
"dependencies": {
"purescript-react": "^1.1.0",
"purescript-aff": "^1.1.0"
"purescript-react": "^2.0.0",
"purescript-aff": "^2.0.2"
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
"commitizen": "^2.8.6",
"cz-conventional-changelog": "^1.2.0",
"ghooks": "^1.3.2",
"pulp": "^9.0.1",
"purescript": "^0.9.3",
"purescript-psa": "^0.3.9",
"pulp": "^10.0.0",
"purescript": "^0.10.4",
"purescript-psa": "^0.4.0",
"semantic-release": "^4.3.5"
},
"config": {
Expand Down
24 changes: 12 additions & 12 deletions src/Carpenter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ module Carpenter
import Prelude
import React as React
import Control.Monad.Aff (launchAff, makeAff, Aff)
import Control.Monad.Aff.Unsafe (unsafeInterleaveAff)
import Control.Monad.Aff.Unsafe (unsafeCoerceAff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Unsafe (unsafeInterleaveEff)
import Control.Monad.Eff.Unsafe (unsafeCoerceEff)

type CarpenterEffects eff = (props :: React.ReactProps, state :: React.ReactState React.ReadWrite | eff)

Expand Down Expand Up @@ -77,16 +77,16 @@ spec state update render = React.spec state (getReactRender update render)

-- | Constructs a React component spec based on an initial state,
-- | an initial action, an update function and a render function.
spec' :: ∀ state props action eff. state -> action -> Update state props action eff -> Render state props action -> React.ReactSpec props state eff
spec' :: ∀ st ps act eff. st -> act -> Update st ps act eff -> Render st ps act -> React.ReactSpec ps st eff
spec' state action update render = (React.spec state (getReactRender update render)) { componentWillMount = componentWillMount }
where
componentWillMount :: React.ComponentWillMount props state eff
componentWillMount :: React.ComponentWillMount ps st eff
componentWillMount this = void $ do
props <- React.getProps this
state <- React.readState this
props' <- React.getProps this
state' <- React.readState this
let yield = mkYielder this
let dispatch = mkDispatcher this update yield
unsafeInterleaveEff (launchAff (update yield dispatch action props state))
unsafeCoerceEff (launchAff (update yield dispatch action props' state'))

-- | A default implementation for the update function which does not perform
-- | any changes to the state, that is, ignores all actions.
Expand All @@ -96,12 +96,12 @@ defaultUpdate _ _ _ _ = pure
-- | Generates an update function for testing with mock `yield` and `dispatch`
-- | functions, which do not depend on React, but return the modified state and
-- | behave as expected.
mockUpdate :: ∀ state props action eff. Update state props action eff -> action -> props -> state -> Aff eff state
mockUpdate update action props state = unsafeInterleaveAff (update mockYield mockDispatch action props state)
mockUpdate :: ∀ st ps act eff. Update st ps act eff -> act -> ps -> st -> Aff eff st
mockUpdate update action props state = unsafeCoerceAff (update mockYield mockDispatch action props state)
where
mockYield f = pure (f state)
mockDispatch :: Dispatcher action
mockDispatch action = void $ unsafeInterleaveEff (launchAff (update mockYield mockDispatch action props state))
mockDispatch :: Dispatcher act
mockDispatch action' = void $ unsafeCoerceEff (launchAff (update mockYield mockDispatch action' props state))

--
--
Expand All @@ -121,7 +121,7 @@ mkDispatcher
mkDispatcher this update yield = dispatch
where
dispatch :: Dispatcher action
dispatch action = void $ unsafeInterleaveEff $ launchAff do
dispatch action = void $ unsafeCoerceEff $ launchAff do
props <- liftEff $ React.getProps this
state <- liftEff $ React.readState this
update yield dispatch action props state
Expand Down
16 changes: 8 additions & 8 deletions src/Carpenter/Cedar.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import Prelude
import React as React
import Carpenter (Yielder, Dispatcher, Render, Update, EventHandler)
import Control.Monad.Aff (Aff, makeAff, launchAff)
import Control.Monad.Aff.Unsafe (unsafeInterleaveAff)
import Control.Monad.Aff.Unsafe (unsafeCoerceAff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Unsafe (unsafeInterleaveEff)
import Control.Monad.Eff.Unsafe (unsafeCoerceEff)

-- | Type synonym for internal props of Cedar components.
type CedarProps state action =
Expand Down Expand Up @@ -91,7 +91,7 @@ cedarSpec' action update render = reactSpec
state <- React.readState this
let yield = mkYielder this
let dispatch = mkDispatcher this update yield
unsafeInterleaveEff (launchAff (update yield dispatch action props state))
unsafeCoerceEff (launchAff (update yield dispatch action props state))

-- | Creates an element of the specificed React class with initial state
-- | and children, and captures its dispatched actions.
Expand Down Expand Up @@ -158,13 +158,13 @@ ignore' reactClass state = React.createElement reactClass {initialState: state,
-- | Generates an update function for testing with mock `yield` and `dispatch`
-- | functions, which do not depend on React, but return the modified state and
-- | behave as expected.
mockUpdate :: ∀ state action eff. Update state (CedarProps state action) action eff -> action -> state -> Aff eff state
mockUpdate update action state = unsafeInterleaveAff (update mockYield mockDispatch action props state)
mockUpdate :: ∀ st act eff. Update st (CedarProps st act) act eff -> act -> st -> Aff eff st
mockUpdate update action state = unsafeCoerceAff (update mockYield mockDispatch action props state)
where
props = { initialState: state, handler: Ignore }
mockYield f = pure (f state)
mockDispatch :: Dispatcher action
mockDispatch action = void $ unsafeInterleaveEff (launchAff (update mockYield mockDispatch action props state))
mockDispatch :: Dispatcher act
mockDispatch action' = void $ unsafeCoerceEff (launchAff (update mockYield mockDispatch action' props state))

--
--
Expand All @@ -184,7 +184,7 @@ mkDispatcher
mkDispatcher this update yield = dispatch
where
dispatch :: Dispatcher action
dispatch action = void $ unsafeInterleaveEff $ launchAff do
dispatch action = void $ unsafeCoerceEff $ launchAff do
props <- liftEff $ React.getProps this
state <- liftEff $ React.readState this
case props.handler of
Expand Down