Skip to content

Commit 77aca4e

Browse files
committed
Adding arguments to lifecycle methods
- componentWillReceiveProps(nextProps) - shouldComponentUpdate(nextProps, nextState) - componentWillUpdate(nextProps, nextState) - componentDidUpdate(prevProps, prevState)
1 parent ca42942 commit 77aca4e

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/React.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,34 @@ exports.mkUI = function(ss) {
4141
if (s === "displayName") {
4242
result[s] = ss[s];
4343
}
44+
else if (s === "componentWillReceiveProps") {
45+
result[s] = (function(impl) {
46+
return function(nextProps) {
47+
return impl(this)(nextProps)();
48+
}
49+
})(ss[s]);
50+
}
51+
else if (s === "shouldComponentUpdate") {
52+
result[s] = (function(impl) {
53+
return function(nextProps, nextState) {
54+
return impl(this)(nextProps)(nextState.state)();
55+
}
56+
})(ss[s]);
57+
}
58+
else if (s === "componentWillUpdate") {
59+
result[s] = (function(impl) {
60+
return function(nextProps, nextState) {
61+
return impl(this)(nextProps)(nextState.state)();
62+
}
63+
})(ss[s]);
64+
}
65+
else if (s === "componentDidUpdate") {
66+
result[s] = (function(impl) {
67+
return function(prevProps, prevState) {
68+
return impl(this)(prevProps)(prevState.state)();
69+
}
70+
})(ss[s]);
71+
}
4472
else {
4573
result[s] = (function(impl) {
4674
return function() {

src/React.purs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,27 +167,34 @@ type UISpec props state eff =
167167
) Unit
168168
, componentWillReceiveProps
169169
:: UIRef ->
170+
props ->
170171
Eff ( props :: ReactProps props
171172
, state :: ReactState ReadWrite state
172173
, refs :: ReactRefs ReadOnly
173174
| eff
174175
) Unit
175176
, shouldComponentUpdate
176177
:: UIRef ->
178+
props ->
179+
state ->
177180
Eff ( props :: ReactProps props
178181
, state :: ReactState ReadWrite state
179182
, refs :: ReactRefs ReadOnly
180183
| eff
181184
) Boolean
182185
, componentWillUpdate
183186
:: UIRef ->
187+
props ->
188+
state ->
184189
Eff ( props :: ReactProps props
185190
, state :: ReactState ReadWrite state
186191
, refs :: ReactRefs ReadOnly
187192
| eff
188193
) Unit
189194
, componentDidUpdate
190195
:: UIRef ->
196+
props ->
197+
state ->
191198
Eff ( props :: ReactProps props
192199
, state :: ReactState ReadOnly state
193200
, refs :: ReactRefs ReadOnly
@@ -210,10 +217,10 @@ spec st render =
210217
, getInitialState: \_ -> pure st
211218
, componentWillMount: \_ -> return unit
212219
, componentDidMount: \_ -> return unit
213-
, componentWillReceiveProps: \_ -> return unit
214-
, shouldComponentUpdate: \_ -> return true
215-
, componentWillUpdate: \_ -> return unit
216-
, componentDidUpdate: \_ -> return unit
220+
, componentWillReceiveProps: \_ _ -> return unit
221+
, shouldComponentUpdate: \_ _ _ -> return true
222+
, componentWillUpdate: \_ _ _ -> return unit
223+
, componentDidUpdate: \_ _ _ -> return unit
217224
, componentWillUnmount: \_ -> return unit
218225
}
219226

0 commit comments

Comments
 (0)