|
1 |
| -import WeakMap from 'core-js/library/es6/weak-map'; |
| 1 | +import find from 'lodash/find'; |
2 | 2 | import createPrototypeProxy from './createPrototypeProxy';
|
3 | 3 | import bindAutoBindMethods from './bindAutoBindMethods';
|
4 | 4 | import deleteUnknownAutoBindMethods from './deleteUnknownAutoBindMethods';
|
@@ -28,13 +28,23 @@ function isEqualDescriptor(a, b) {
|
28 | 28 | return true;
|
29 | 29 | }
|
30 | 30 |
|
31 |
| -let allProxies = new WeakMap(); |
| 31 | +// This was originally a WeakMap but we had issues with React Native: |
| 32 | +// https://github.com/gaearon/react-proxy/issues/50#issuecomment-192928066 |
| 33 | +let allProxies = []; |
| 34 | +function findProxy(Component) { |
| 35 | + const pair = allProxies.find(([key]) => key === Component); |
| 36 | + return pair ? pair[1] : null; |
| 37 | +} |
| 38 | +function addProxy(Component, proxy) { |
| 39 | + allProxies.push([Component, proxy]); |
| 40 | +} |
32 | 41 |
|
33 | 42 | function proxyClass(InitialComponent) {
|
34 | 43 | // Prevent double wrapping.
|
35 | 44 | // Given a proxy class, return the existing proxy managing it.
|
36 |
| - if (allProxies.has(InitialComponent)) { |
37 |
| - return allProxies.get(InitialComponent); |
| 45 | + var existingProxy = findProxy(InitialComponent); |
| 46 | + if (existingProxy) { |
| 47 | + return existingProxy; |
38 | 48 | }
|
39 | 49 |
|
40 | 50 | let CurrentComponent;
|
@@ -97,8 +107,9 @@ function proxyClass(InitialComponent) {
|
97 | 107 | }
|
98 | 108 |
|
99 | 109 | // Prevent proxy cycles
|
100 |
| - if (allProxies.has(NextComponent)) { |
101 |
| - return update(allProxies.get(NextComponent).__getCurrent()); |
| 110 | + var existingProxy = findProxy(NextComponent); |
| 111 | + if (existingProxy) { |
| 112 | + return update(existingProxy.__getCurrent()); |
102 | 113 | }
|
103 | 114 |
|
104 | 115 | // Save the next constructor so we call it
|
@@ -176,7 +187,7 @@ function proxyClass(InitialComponent) {
|
176 | 187 | update(InitialComponent);
|
177 | 188 |
|
178 | 189 | const proxy = { get, update };
|
179 |
| - allProxies.set(ProxyComponent, proxy); |
| 190 | + addProxy(ProxyComponent, proxy); |
180 | 191 |
|
181 | 192 | Object.defineProperty(proxy, '__getCurrent', {
|
182 | 193 | configurable: false,
|
|
0 commit comments