-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdecorators.js
More file actions
29 lines (25 loc) · 743 Bytes
/
decorators.js
File metadata and controls
29 lines (25 loc) · 743 Bytes
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
import React from 'react-native';
function AssertReact(Component) {
if (!(Component.prototype instanceof React.Component)) {
throw new Error('Specified target is not a React component.');
}
}
export function Debug(Component) {
AssertReact(Component);
const original = Component.prototype.render;
Component.prototype.render = function() {
console.log(
`
Props: ${JSON.stringify(this.props)}
State: ${JSON.stringify(this.state)}
`
);
return original.apply(this, arguments);
};
return Component;
}
export function PureRender(Component) {
AssertReact(Component);
Component.prototype.shouldComponentUpdate = React.addons.PureRenderMixin.shouldComponentUpdate;
return Component;
}