Skip to content

Adds a spec constructor function with getInitialState #49

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
Oct 18, 2015
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
10 changes: 9 additions & 1 deletion docs/React.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,15 @@ A specification of a component.
spec :: forall props state eff. state -> Render props state eff -> ReactSpec props state eff
```

Create a component specification.
Create a component specification with a provided state.

#### `spec'`

``` purescript
spec' :: forall props state eff. GetInitialState props state eff -> Render props state eff -> ReactSpec props state eff
```

Create a component specification with a get initial state function.

#### `ReactClass`

Expand Down
28 changes: 16 additions & 12 deletions src/React.purs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module React

, EventHandlerContext()

, spec
, spec, spec'

, getProps
, getRefs
Expand Down Expand Up @@ -244,19 +244,23 @@ type ReactSpec props state eff =
, componentWillUnmount :: ComponentWillUnmount props state eff
}

-- | Create a component specification.
-- | Create a component specification with a provided state.
spec :: forall props state eff. state -> Render props state eff -> ReactSpec props state eff
spec st renderFn =
{ render: renderFn
, displayName: ""
, getInitialState: \_ -> pure st
, componentWillMount: \_ -> return unit
, componentDidMount: \_ -> return unit
spec state = spec' (\_ -> pure state)

-- | Create a component specification with a get initial state function.
spec' :: forall props state eff. GetInitialState props state eff -> Render props state eff -> ReactSpec props state eff
spec' getInitialState renderFn =
{ render: renderFn
, displayName: ""
, getInitialState: getInitialState
, componentWillMount: \_ -> return unit
, componentDidMount: \_ -> return unit
, componentWillReceiveProps: \_ _ -> return unit
, shouldComponentUpdate: \_ _ _ -> return true
, componentWillUpdate: \_ _ _ -> return unit
, componentDidUpdate: \_ _ _ -> return unit
, componentWillUnmount: \_ -> return unit
, shouldComponentUpdate: \_ _ _ -> return true
, componentWillUpdate: \_ _ _ -> return unit
, componentDidUpdate: \_ _ _ -> return unit
, componentWillUnmount: \_ -> return unit
}

-- | React class for components.
Expand Down