Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 8d849b5

Browse files
committed
undid useProxy change
1 parent 5055f75 commit 8d849b5

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

packages/react/src/hooks/useProxy.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import {
1616
AgileOutputHookType,
1717
} from './useAgile';
1818
import { LogCodeManager } from '../logCodeManager';
19+
1920
// TODO https://stackoverflow.com/questions/68148235/require-module-inside-a-function-doesnt-work
21+
let proxyPackage: any = null;
2022
try {
21-
require('@agile-ts/proxytree');
23+
proxyPackage = require('@agile-ts/proxytree');
2224
} catch (e) {
23-
LogCodeManager.log('31:03:00');
25+
// empty catch block
2426
}
25-
import { ProxyTree } from '@agile-ts/proxytree';
2627

2728
/**
2829
* A React Hook for binding the most relevant value of multiple Agile Instances
@@ -94,9 +95,14 @@ export function useProxy<
9495
// If proxyBased and the value is of the type object.
9596
// Wrap a Proxy around the object to track the accessed properties.
9697
if (isValidObject(value, true)) {
97-
const proxyTree = new ProxyTree(value);
98-
proxyTreeWeakMap.set(dep, proxyTree);
99-
return proxyTree.proxy;
98+
if (proxyPackage != null) {
99+
const { ProxyTree } = proxyPackage;
100+
const proxyTree = new ProxyTree(value);
101+
proxyTreeWeakMap.set(dep, proxyTree);
102+
return proxyTree.proxy;
103+
} else {
104+
LogCodeManager.log('31:03:00');
105+
}
100106
}
101107

102108
return value;
@@ -117,13 +123,15 @@ export function useProxy<
117123
// because the 'useIsomorphicLayoutEffect' is called after the rerender.
118124
// -> All used paths in the UI-Component were successfully tracked.
119125
let proxyWeakMap: ProxyWeakMapType | undefined = undefined;
120-
proxyWeakMap = new WeakMap();
121-
for (const observer of observers) {
122-
const proxyTree = proxyTreeWeakMap.get(observer);
123-
if (proxyTree != null) {
124-
proxyWeakMap.set(observer, {
125-
paths: proxyTree.getUsedRoutes() as any,
126-
});
126+
if (proxyPackage != null) {
127+
proxyWeakMap = new WeakMap();
128+
for (const observer of observers) {
129+
const proxyTree = proxyTreeWeakMap.get(observer);
130+
if (proxyTree != null) {
131+
proxyWeakMap.set(observer, {
132+
paths: proxyTree.getUsedRoutes() as any,
133+
});
134+
}
127135
}
128136
}
129137

0 commit comments

Comments
 (0)