Skip to content

Commit 37e40fb

Browse files
committed
Minifier-friendly references to properties
1 parent dc20cc0 commit 37e40fb

File tree

1 file changed

+21
-37
lines changed

1 file changed

+21
-37
lines changed

src/React.js

+21-37
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,14 @@
44
var React = require("react");
55

66
function createClass(baseClass) {
7-
function bindProperty(instance, prop, value) {
8-
switch (prop) {
9-
case 'state':
10-
case 'render':
11-
case 'componentDidMount':
12-
case 'componentWillUnmount':
13-
instance[prop] = value;
14-
break;
15-
16-
case 'componentDidCatch':
17-
case 'componentWillUpdate':
18-
case 'shouldComponentUpdate':
19-
case 'getSnapshotBeforeUpdate':
20-
instance[prop] = function (a, b) { return value(a)(b)(); };
21-
break;
22-
23-
case 'componentDidUpdate':
24-
instance[prop] = function (a, b, c) { return value(a)(b)(c)(); };
25-
break;
26-
27-
case 'unsafeComponentWillMount':
28-
instance['UNSAFE_componentWillMount'] = value;
29-
break;
30-
31-
case 'unsafeComponentWillReceiveProps':
32-
instance['UNSAFE_componentWillReceiveProps'] = function (a) { return value(a)(); };
33-
break;
34-
35-
case 'unsafeComponentWillUpdate':
36-
instance['UNSAFE_componentWillUpdate'] = function (a, b) { return value(a)(b)(); };
37-
break;
38-
39-
default:
40-
throw new Error('[purescript-react] Not a component property: ' + prop);
7+
function curry2(f) {
8+
return f === undefined ? f : function (a, b) {
9+
return f(a)(b)
10+
}
11+
}
12+
function curry3(f) {
13+
return f === undefined ? f : function (a, b, c) {
14+
return f(a)(b)(c)
4115
}
4216
}
4317

@@ -46,9 +20,19 @@ function createClass(baseClass) {
4620
var Constructor = function (props) {
4721
baseClass.call(this, props);
4822
var spec = ctrFn(this)();
49-
for (var k in spec) {
50-
bindProperty(this, k, spec[k]);
51-
}
23+
24+
this.state = spec.state;
25+
this.render = spec.render;
26+
this.componentDidMount = spec.componentDidMount;
27+
this.componentWillUnmount = spec.componentWillUnmount;
28+
this.componentDidCatch = curry2(spec.componentDidCatch);
29+
this.componentWillUpdate = curry2(spec.componentWillUpdate);
30+
this.shouldComponentUpdate = curry2(spec.shouldComponentUpdate);
31+
this.getSnapshotBeforeUpdate = curry2(spec.getSnapshotBeforeUpdate);
32+
this.componentDidUpdate = curry3(spec.componentDidUpdate);
33+
this.UNSAFE_componentWillMount = spec.unsafeComponentWillMount;
34+
this.UNSAFE_componentWillReceiveProps = curry2(spec.unsafeComponentWillReceiveProps);
35+
this.UNSAFE_componentWillUpdate = curry3(spec.unsafeComponentWillUpdate);
5236
};
5337

5438
Constructor.displayName = displayName;

0 commit comments

Comments
 (0)