Skip to content

Commit 8f99b18

Browse files
committed
Merge pull request #49 from ethul/topic/get-initial-state
Adds a spec constructor function with getInitialState
2 parents cbe6f58 + d385e5b commit 8f99b18

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

docs/React.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,15 @@ A specification of a component.
230230
spec :: forall props state eff. state -> Render props state eff -> ReactSpec props state eff
231231
```
232232

233-
Create a component specification.
233+
Create a component specification with a provided state.
234+
235+
#### `spec'`
236+
237+
``` purescript
238+
spec' :: forall props state eff. GetInitialState props state eff -> Render props state eff -> ReactSpec props state eff
239+
```
240+
241+
Create a component specification with a get initial state function.
234242

235243
#### `ReactClass`
236244

src/React.purs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module React
3838

3939
, EventHandlerContext()
4040

41-
, spec
41+
, spec, spec'
4242

4343
, getProps
4444
, getRefs
@@ -244,19 +244,23 @@ type ReactSpec props state eff =
244244
, componentWillUnmount :: ComponentWillUnmount props state eff
245245
}
246246

247-
-- | Create a component specification.
247+
-- | Create a component specification with a provided state.
248248
spec :: forall props state eff. state -> Render props state eff -> ReactSpec props state eff
249-
spec st renderFn =
250-
{ render: renderFn
251-
, displayName: ""
252-
, getInitialState: \_ -> pure st
253-
, componentWillMount: \_ -> return unit
254-
, componentDidMount: \_ -> return unit
249+
spec state = spec' (\_ -> pure state)
250+
251+
-- | Create a component specification with a get initial state function.
252+
spec' :: forall props state eff. GetInitialState props state eff -> Render props state eff -> ReactSpec props state eff
253+
spec' getInitialState renderFn =
254+
{ render: renderFn
255+
, displayName: ""
256+
, getInitialState: getInitialState
257+
, componentWillMount: \_ -> return unit
258+
, componentDidMount: \_ -> return unit
255259
, componentWillReceiveProps: \_ _ -> return unit
256-
, shouldComponentUpdate: \_ _ _ -> return true
257-
, componentWillUpdate: \_ _ _ -> return unit
258-
, componentDidUpdate: \_ _ _ -> return unit
259-
, componentWillUnmount: \_ -> return unit
260+
, shouldComponentUpdate: \_ _ _ -> return true
261+
, componentWillUpdate: \_ _ _ -> return unit
262+
, componentDidUpdate: \_ _ _ -> return unit
263+
, componentWillUnmount: \_ -> return unit
260264
}
261265

262266
-- | React class for components.

0 commit comments

Comments
 (0)