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