forked from purescript-contrib/purescript-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReact.js
More file actions
165 lines (139 loc) · 3.62 KB
/
React.js
File metadata and controls
165 lines (139 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* global exports */
"use strict";
var React = require("react");
function createClass(baseClass) {
function bindProperty(instance, prop, value) {
switch (prop) {
case 'componentDidMount':
case 'componentDidUpdate':
case 'componentWillMount':
case 'componentWillUnmount':
case 'render':
case 'state':
instance[prop] = value;
break;
case 'componentWillReceiveProps':
instance[prop] = function (a) { return value(a)(); };
break;
case 'componentDidCatch':
case 'componentWillUpdate':
case 'shouldComponentUpdate':
instance[prop] = function (a, b) { return value(a)(b)(); };
break;
default:
throw new Error('Not a component property: ' + prop);
}
}
return function (displayName) {
return function (ctrFn) {
var Constructor = function (props) {
baseClass.call(this, props);
var spec = ctrFn(this)();
for (var k in spec) {
bindProperty(this, k, spec[k]);
}
};
Constructor.displayName = displayName;
Constructor.prototype = Object.create(baseClass.prototype);
Constructor.prototype.constructor = Constructor;
return Constructor;
};
};
}
exports.componentImpl = createClass(React.Component);
exports.pureComponentImpl = createClass(React.PureComponent);
exports.statelessComponent = function(x) { return x; };
exports.fragment = React.Fragment;
function getProps(this_) {
return function(){
return this_.props;
};
}
exports.getProps = getProps;
exports.childrenToArray = React.Children.toArray
exports.childrenCount = React.Children.count;
function writeState(this_) {
return function(state){
return function(){
this_.setState(state);
return state;
};
};
}
exports.writeState = writeState;
function writeStateWithCallback(this_, cb) {
return function(state){
return function(cb){
return function() {
this_.setState(state, cb);
return state;
};
};
};
}
exports.writeStateWithCallback = writeStateWithCallback;
function readState(this_) {
return function(){
return this_.state;
};
}
exports.readState = readState;
function transformState(this_){
return function(update){
return function(){
this_.setState(function(old, props){
return update(old);
});
};
};
}
exports.transformState = transformState;
function forceUpdateCbImpl(this_, cb) {
this_.forceUpdate(function() {
return cb();
});
return {};
};
exports.forceUpdateCbImpl = forceUpdateCbImpl;
function handle(f) {
return function(e){
return f(e)();
};
};
exports.handle = handle;
function createElement(class_) {
return function(props){
return function(children){
return React.createElement.apply(React, [class_, props].concat(children));
};
};
}
exports.createElementImpl = createElement;
exports.createElementTagName = createElement;
function createLeafElement(class_) {
return function(props) {
return React.createElement(class_, props);
};
}
exports.createLeafElementImpl = createLeafElement;
function createElementDynamic(class_) {
return function(props) {
return function(children){
return React.createElement(class_, props, children);
};
};
};
exports.createElementDynamicImpl = createElementDynamic;
exports.createElementTagNameDynamic = createElementDynamic;
function preventDefault(event) {
return function() {
event.preventDefault();
};
};
exports.preventDefault = preventDefault;
function stopPropagation(event) {
return function() {
event.stopPropagation();
};
};
exports.stopPropagation = stopPropagation;