Skip to content

Simplify #10

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

Merged
merged 21 commits into from
Oct 2, 2017
Merged
Changes from 1 commit
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
30 changes: 13 additions & 17 deletions src/React/Redux.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module React.Redux
( ReduxReactClass
, ReduxReactClass'
( ReactClass
, ReactClass'
, ReduxEffect
, REDUX
, Reducer
Expand All @@ -13,10 +13,9 @@ module React.Redux
, Store
, connect
, connect_
, createProviderElement
, createProviderElement_
, createElement
, createElement_
, createProviderElement
, createStore
, createStore'
, dispatch
Expand All @@ -41,7 +40,7 @@ import React as React

import Unsafe.Coerce (unsafeCoerce)

type ReduxReactClass' state props = ReduxReactClass state Unit props
type ReactClass' state props = ReactClass state Unit props

type Reducer' action state = Reducer action state state

Expand Down Expand Up @@ -87,30 +86,27 @@ instance semigroupReducer :: Semigroup state' => Semigroup (Reducer action state
instance monoidReducer :: Monoid state' => Monoid (Reducer action state state') where
mempty = Reducer (const (const (mempty)))

createProviderElement :: forall action props props' state. Store action state -> ReduxReactClass state props props' -> props -> Array React.ReactElement -> React.ReactElement
createProviderElement store reduxClass props children = React.createElement providerClass { store } [ createElement reduxClass props children ]

createProviderElement_ :: forall action props state. Store action state -> ReduxReactClass' state props -> React.ReactElement
createProviderElement_ store reduxClass = React.createElement providerClass { store } [ createElement_ reduxClass [] ]

connect :: forall props props' state. Getter' (Tuple state props) props' -> React.ReactClass props' -> ReduxReactClass state props props'
connect :: forall props props' state. Getter' (Tuple state props) props' -> React.ReactClass props' -> ReactClass state props props'
connect slens class_ = runFn3 connectFn Tuple (view slens) class_

connect_ :: forall props state. Getter' state props -> React.ReactClass props -> ReduxReactClass' state props
connect_ :: forall props state. Getter' state props -> React.ReactClass props -> ReactClass' state props
connect_ slens class_ = connect slens' class_
where
slens' :: Getter' (Tuple state Unit) props
slens' = to (view slens <<< fst)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not slens <<< _1 _1 is in Data.Lens.Lens.Tuple

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are looking at an outdated version here. connect does not use Getter' in the latest version.


createElement :: forall state props props'. ReduxReactClass state props props' -> props -> Array React.ReactElement -> React.ReactElement
createElement :: forall state props props'. ReactClass state props props' -> props -> Array React.ReactElement -> React.ReactElement
createElement reduxClass = React.createElement reactClass
where
reactClass :: React.ReactClass props
reactClass = unsafeCoerce reduxClass

createElement_ :: forall state props. ReduxReactClass' state props -> Array React.ReactElement -> React.ReactElement
createElement_ :: forall state props. ReactClass' state props -> Array React.ReactElement -> React.ReactElement
createElement_ reduxClass = createElement reduxClass unit

createProviderElement :: forall action state. Store action state -> Array React.ReactElement -> React.ReactElement
createProviderElement store = React.createElement providerClass { store }

createStore :: forall eff action state. Reducer' action state -> state -> Enhancer eff action state -> Eff (ReduxEffect eff) (Store action state)
createStore = runFn3 createStoreFn

Expand Down Expand Up @@ -139,9 +135,9 @@ foreign import data REDUX :: Effect

foreign import data Store :: Type -> Type -> Type

foreign import data ReduxReactClass :: Type -> Type -> Type -> Type
foreign import data ReactClass :: Type -> Type -> Type -> Type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will affect error messages. PureScript doesn't show qualified type names (or maybe it's just a problem of psa?). This might lead to some confusion when reading an error message.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And for this, I think you are looking at an outdated version. This has been renamed to ConnectClass.


foreign import connectFn :: forall state props props'. Fn3 (state -> props -> Tuple state props) (Tuple state props -> props') (React.ReactClass props') (ReduxReactClass state props props')
foreign import connectFn :: forall state props props'. Fn3 (state -> props -> Tuple state props) (Tuple state props -> props') (React.ReactClass props') (ReactClass state props props')

foreign import dispatchFn :: forall eff action props state. Fn2 (React.ReactThis props state) action (Eff (ReduxEffect eff) action)

Expand Down