Skip to content

Topic/lifecycle methods #39

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 2 commits into from
Aug 31, 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
2 changes: 1 addition & 1 deletion docs/React.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ A rendering function.
#### `UISpec`

``` purescript
type UISpec props state eff = { render :: Render props state eff, displayName :: String, getInitialState :: UIRef -> Eff (props :: ReactProps props, state :: ReactState Disallowed state, refs :: ReactRefs Disallowed | eff) state, componentWillMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs Disallowed | eff) Unit, componentDidMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillReceiveProps :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, shouldComponentUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Boolean, componentWillUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentDidUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillUnmount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit }
type UISpec props state eff = { render :: Render props state eff, displayName :: String, getInitialState :: UIRef -> Eff (props :: ReactProps props, state :: ReactState Disallowed state, refs :: ReactRefs Disallowed | eff) state, componentWillMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs Disallowed | eff) Unit, componentDidMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillReceiveProps :: UIRef -> props -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, shouldComponentUpdate :: UIRef -> props -> state -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Boolean, componentWillUpdate :: UIRef -> props -> state -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentDidUpdate :: UIRef -> props -> state -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillUnmount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit }
```

A specification of a component.
Expand Down
28 changes: 28 additions & 0 deletions src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ exports.mkUI = function(ss) {
if (s === "displayName") {
result[s] = ss[s];
}
else if (s === "componentWillReceiveProps") {
result[s] = (function(impl) {
return function(nextProps) {
return impl(this)(nextProps)();
}
})(ss[s]);
}
else if (s === "shouldComponentUpdate") {
result[s] = (function(impl) {
return function(nextProps, nextState) {
return impl(this)(nextProps)(nextState.state)();
}
})(ss[s]);
}
else if (s === "componentWillUpdate") {
result[s] = (function(impl) {
return function(nextProps, nextState) {
return impl(this)(nextProps)(nextState.state)();
}
})(ss[s]);
}
else if (s === "componentDidUpdate") {
result[s] = (function(impl) {
return function(prevProps, prevState) {
return impl(this)(prevProps)(prevState.state)();
}
})(ss[s]);
}
else {
result[s] = (function(impl) {
return function() {
Expand Down
15 changes: 11 additions & 4 deletions src/React.purs
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,34 @@ type UISpec props state eff =
) Unit
, componentWillReceiveProps
:: UIRef ->
props ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Unit
, shouldComponentUpdate
:: UIRef ->
props ->
state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Boolean
, componentWillUpdate
:: UIRef ->
props ->
state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadWrite state
, refs :: ReactRefs ReadOnly
| eff
) Unit
, componentDidUpdate
:: UIRef ->
props ->
state ->
Eff ( props :: ReactProps props
, state :: ReactState ReadOnly state
, refs :: ReactRefs ReadOnly
Expand All @@ -210,10 +217,10 @@ spec st render =
, getInitialState: \_ -> pure st
, componentWillMount: \_ -> return unit
, componentDidMount: \_ -> return unit
, componentWillReceiveProps: \_ -> return unit
, shouldComponentUpdate: \_ -> return true
, componentWillUpdate: \_ -> return unit
, componentDidUpdate: \_ -> return unit
, componentWillReceiveProps: \_ _ -> return unit
, shouldComponentUpdate: \_ _ _ -> return true
, componentWillUpdate: \_ _ _ -> return unit
, componentDidUpdate: \_ _ _ -> return unit
, componentWillUnmount: \_ -> return unit
}

Expand Down