-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (30 loc) · 1.25 KB
/
index.js
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
import { Component } from 'react';
import { isObject } from './utils';
export default class PureComponent extends Component {
shouldComponentUpdate(nextProps) {
const currentPropsNames = Object.getOwnPropertyNames(this.props);
const nextPropsNames = Object.getOwnPropertyNames(nextProps);
if(currentPropsNames.length !== nextPropsNames.length) {
return true
}
for(const key in nextProps) {
if(nextProps.hasOwnProperty(key)) {
if(!(nextProps[key] instanceof Function)) {
if (isObject(nextProps[key]) || Array.isArray(nextProps[key]) ) {
if(nextProps[key] !== this.props[key] && JSON.stringify(nextProps[key]) !== JSON.stringify(this.props[key])) {
return true;
}
} else if(nextProps[key] !== this.props[key]) {
return true;
}
}
else {
if (!this.props[key] || !nextProps[key].name || (nextProps[key].name !== this.props[key].name)) {
return true;
}
}
}
}
return false;
}
}