Skip to content

Commit

Permalink
Merge pull request #39 from ethul/topic/lifecycle-methods
Browse files Browse the repository at this point in the history
Topic/lifecycle methods
  • Loading branch information
paf31 committed Aug 31, 2015
2 parents 91d07ac + 0d29bf3 commit e1037c9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
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 @@ -47,6 +47,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 @@ -170,27 +170,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 @@ -216,10 +223,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

0 comments on commit e1037c9

Please sign in to comment.