-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatch.js
More file actions
148 lines (140 loc) · 4.59 KB
/
catch.js
File metadata and controls
148 lines (140 loc) · 4.59 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
export default function catchErrors({ filename, components, imports }) {
const [React] = imports;
if (!React || !React.Component) {
throw new Error('imports[0] for react-catch-errors does not look like React.');
}
return function returnCatchErrors(ReactClass) {
//setState
var hf_render = ReactClass.prototype.setState;
Object.defineProperty(ReactClass.prototype, 'setState', {
configurable: true,
writable: true,
value: function tryRender() {
if(arguments[1]){
var funcs =arguments[1];
arguments[1]= function(){
try{
return funcs.apply(this,arguments)
}catch(err){
console.error(err)
}
}
}
return hf_render.apply(this,arguments);
}
});
//render
if(ReactClass.prototype.render){
const h_render = ReactClass.prototype.render;
Object.defineProperty(ReactClass.prototype, 'render', {
configurable: true,
writable:true,
value: function tryRender() {
try {
return h_render.apply(this, arguments);
} catch (err) {
console.error(err);
return React.createElement('div', { toWhat: 'world'}, err+"");
}
}
});
}
//componentWillUpdate
if(ReactClass.prototype.componentWillUpdate){
const h_componentWillUpdate = ReactClass.prototype.componentWillUpdate;
Object.defineProperty(ReactClass.prototype, 'componentWillUpdate', {
configurable: true,
writable:true,
value: function tryRender() {
try{
if(!h_componentWillUpdate) return
return h_componentWillUpdate.apply(this, arguments);
}catch(err){
console.error(err)
}
}
});
}
//componentWillReceiveProps
if(ReactClass.prototype.componentWillReceiveProps){
var h_componentWillReceiveProps =ReactClass.prototype.componentWillReceiveProps;
Object.defineProperty(ReactClass.prototype, 'componentWillReceiveProps', {
configurable: true,
writable:true,
value: function tryRender() {
try{
if(!h_componentWillReceiveProps) return
return h_componentWillReceiveProps.apply(this, arguments);
}catch(err){
console.error(err)
}
}
});
}
//componentDidUpdate
if(ReactClass.prototype.componentDidUpdate){
var h_componentDidUpdate =ReactClass.prototype.componentDidUpdate;
Object.defineProperty(ReactClass.prototype, 'componentDidUpdate', {
configurable: true,
writable:true,
value: function tryRender() {
try{
if(!h_componentDidUpdate) return
return h_componentDidUpdate.apply(this, arguments);
}catch(err){
console.error(err)
}
}
});
}
//componentWillUnmount
if(ReactClass.prototype.componentWillUnmount){
var h_componentWillUnmount =ReactClass.prototype.componentWillUnmount;
Object.defineProperty(ReactClass.prototype, 'componentWillUnmount', {
configurable: true,
writable:true,
value: function tryRender() {
try{
if(!h_componentWillUnmount) return
return h_componentWillUnmount.apply(this, arguments);
}catch(err){
console.error(err)
}
}
});
}
//componentWillMount
if(ReactClass.prototype.componentWillMount){
var h_componentWillMount =ReactClass.prototype.componentWillMount;
Object.defineProperty(ReactClass.prototype, 'componentWillMount', {
configurable: true,
writable:true,
value: function tryRender() {
try{
if(!h_componentWillMount) return
return h_componentWillMount.apply(this, arguments);
}catch(err){
console.error(err)
}
}
});
}
//componentDidMount
if(ReactClass.prototype.componentDidMount){
var h_componentDidMount =ReactClass.prototype.componentDidMount;
Object.defineProperty(ReactClass.prototype, 'componentDidMount', {
configurable: true,
writable:true,
value: function tryRender() {
try{
if(!h_componentDidMount) return
return h_componentDidMount.apply(this, arguments);
}catch(err){
console.error(err)
}
}
});
}
return ReactClass;
};
}