Skip to content

Commit dfc9ecf

Browse files
committed
Require state to be a record
Fixes #19
1 parent f456cfa commit dfc9ecf

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

Diff for: examples/component/src/Container.purs

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ module Container where
22

33
import Prelude
44

5-
import React.Basic (ReactComponent, createElement, react)
5+
import React.Basic (ReactComponent, createElement, stateless)
66
import React.Basic.DOM as R
77
import ToggleButton as ToggleButton
88

99
component :: ReactComponent Unit
10-
component = react
10+
component = stateless
1111
{ displayName: "Container"
12-
, initialState: unit
13-
, receiveProps: \_ _ _ -> pure unit
14-
, render: \_ _ setState ->
12+
, render: \_ ->
1513
R.div { children: [ createElement ToggleButton.component { on: true }
1614
, createElement ToggleButton.component { on: false }
1715
]

Diff for: generated-docs/React/Basic.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#### `react`
44

55
``` purescript
6-
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
6+
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
77
```
88

99
Create a React component from a _specification_ of that component.

Diff for: src/React/Basic.purs

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import React.Basic.Types as React.Basic.Types
2828
react
2929
:: forall props state fx
3030
. { displayName :: String
31-
, initialState :: state
32-
, receiveProps :: props -> state -> (SetState state fx) -> Eff (react :: ReactFX | fx) Unit
33-
, render :: props -> state -> (SetState state fx) -> JSX
31+
, initialState :: { | state }
32+
, receiveProps :: props -> { | state } -> (SetState state fx) -> Eff (react :: ReactFX | fx) Unit
33+
, render :: props -> { | state } -> (SetState state fx) -> JSX
3434
}
3535
-> ReactComponent props
3636
react { displayName, initialState, receiveProps, render } =
@@ -54,13 +54,13 @@ stateless
5454
stateless { displayName, render } =
5555
react
5656
{ displayName
57-
, initialState: unit
57+
, initialState: {}
5858
, receiveProps: \_ _ _ -> pure unit
5959
, render: \props _ _ -> render props
6060
}
6161

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

6565
-- | Create a `JSX` node from a React component, by providing the props.
6666
createElement
@@ -94,9 +94,9 @@ fragmentKeyed = runFn2 fragmentKeyed_
9494
foreign import component_
9595
:: forall props state fx
9696
. { displayName :: String
97-
, initialState :: state
98-
, receiveProps :: EffFn3 (react :: ReactFX | fx) props state (SetState state fx) Unit
99-
, render :: Fn3 props state (SetState state fx) JSX
97+
, initialState :: { | state }
98+
, receiveProps :: EffFn3 (react :: ReactFX | fx) props { | state } (SetState state fx) Unit
99+
, render :: Fn3 props { | state } (SetState state fx) JSX
100100
}
101101
-> ReactComponent props
102102

0 commit comments

Comments
 (0)