1 | function shouldDeleteClassicInstanceMethod(component, name) {
|
2 | if (component.__reactAutoBindMap.hasOwnProperty(name)) {
|
3 |
|
4 | return false;
|
5 | }
|
6 |
|
7 | if (component[name].__reactBoundArguments !== null) {
|
8 |
|
9 | return false;
|
10 | }
|
11 |
|
12 |
|
13 |
|
14 | return true;
|
15 | }
|
16 |
|
17 | function shouldDeleteModernInstanceMethod(component, name) {
|
18 | const { prototype } = component.constructor;
|
19 | const prototypeDescriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
20 |
|
21 | if (!prototypeDescriptor || !prototypeDescriptor.get) {
|
22 |
|
23 | return false;
|
24 | }
|
25 |
|
26 | if (prototypeDescriptor.get().length !== component[name].length) {
|
27 |
|
28 | return false;
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 | return true;
|
34 | }
|
35 |
|
36 | function shouldDeleteInstanceMethod(component, name) {
|
37 | const descriptor = Object.getOwnPropertyDescriptor(component, name);
|
38 | if (typeof descriptor.value !== 'function') {
|
39 |
|
40 | return;
|
41 | }
|
42 |
|
43 | if (component.__reactAutoBindMap) {
|
44 |
|
45 | return shouldDeleteClassicInstanceMethod(component, name);
|
46 | } else {
|
47 |
|
48 | return shouldDeleteModernInstanceMethod(component, name);
|
49 | }
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | export default function deleteUnknownAutoBindMethods(component) {
|
64 | const names = Object.getOwnPropertyNames(component);
|
65 |
|
66 | names.forEach(name => {
|
67 | if (shouldDeleteInstanceMethod(component, name)) {
|
68 | delete component[name];
|
69 | }
|
70 | });
|
71 | }
|