Skip to content

Require state to be a record #20

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 1 commit into from
Mar 21, 2018
Merged
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
8 changes: 3 additions & 5 deletions examples/component/src/Container.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ module Container where

import Prelude

import React.Basic (ReactComponent, createElement, react)
import React.Basic (ReactComponent, createElement, stateless)
import React.Basic.DOM as R
import ToggleButton as ToggleButton

component :: ReactComponent Unit
component = react
component = stateless
{ displayName: "Container"
, initialState: unit
, receiveProps: \_ _ _ -> pure unit
, render: \_ _ setState ->
, render: \_ ->
R.div { children: [ createElement ToggleButton.component { on: true }
, createElement ToggleButton.component { on: false }
]
Expand Down
2 changes: 1 addition & 1 deletion generated-docs/React/Basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#### `react`

``` purescript
react :: forall props state fx. { displayName :: String, initialState :: state, receiveProps :: props -> state -> (SetState state fx) -> Eff (react :: ReactFX | fx) Unit, render :: props -> state -> (SetState state fx) -> JSX } -> ReactComponent props
react :: forall props state fx. { displayName :: String, initialState :: { | state }, receiveProps :: props -> { | state } -> (SetState state fx) -> Eff (react :: ReactFX | fx) Unit, render :: props -> { | state } -> (SetState state fx) -> JSX } -> ReactComponent props
```

Create a React component from a _specification_ of that component.
Expand Down
16 changes: 8 additions & 8 deletions src/React/Basic.purs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import React.Basic.Types as React.Basic.Types
react
:: forall props state fx
. { displayName :: String
, initialState :: state
, receiveProps :: props -> state -> (SetState state fx) -> Eff (react :: ReactFX | fx) Unit
, render :: props -> state -> (SetState state fx) -> JSX
, initialState :: { | state }
, receiveProps :: props -> { | state } -> (SetState state fx) -> Eff (react :: ReactFX | fx) Unit
, render :: props -> { | state } -> (SetState state fx) -> JSX
}
-> ReactComponent props
react { displayName, initialState, receiveProps, render } =
Expand All @@ -54,13 +54,13 @@ stateless
stateless { displayName, render } =
react
{ displayName
, initialState: unit
, initialState: {}
, receiveProps: \_ _ _ -> pure unit
, render: \props _ _ -> render props
}

-- | SetState uses an update function to modify the current state.
type SetState state fx = (state -> state) -> Eff (react :: ReactFX | fx) Unit
type SetState state fx = ({ | state } -> { | state }) -> Eff (react :: ReactFX | fx) Unit

-- | Create a `JSX` node from a React component, by providing the props.
createElement
Expand Down Expand Up @@ -94,9 +94,9 @@ fragmentKeyed = runFn2 fragmentKeyed_
foreign import component_
:: forall props state fx
. { displayName :: String
, initialState :: state
, receiveProps :: EffFn3 (react :: ReactFX | fx) props state (SetState state fx) Unit
, render :: Fn3 props state (SetState state fx) JSX
, initialState :: { | state }
, receiveProps :: EffFn3 (react :: ReactFX | fx) props { | state } (SetState state fx) Unit
, render :: Fn3 props { | state } (SetState state fx) JSX
}
-> ReactComponent props

Expand Down