Skip to content

Commit

Permalink
fix: Fis feature test for WeakRef fails in browser extensions
Browse files Browse the repository at this point in the history
Removes window object access in `ReactiveValue`.

See #97.
  • Loading branch information
personalizedrefrigerator committed Jan 19, 2025
1 parent e97c937 commit b4a3987
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/js-draw/src/util/ReactiveValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ export abstract class ReactiveValue<T> {
sourceValues: ReactiveValue<any>[],
): ReactiveValue<T> {
const result = new ReactiveValueImpl(callback());
const resultRef = (window as any).WeakRef
? new (window as any).WeakRef(result)
: { deref: () => result };
const resultRef =
typeof WeakRef !== 'undefined' ? new WeakRef(result) : { deref: () => result };

for (const value of sourceValues) {
const listener = value.onUpdate(() => {
Expand Down Expand Up @@ -179,9 +178,7 @@ export abstract class MutableReactiveValue<T> extends ReactiveValue<T> {
propertyName: Name,
): MutableReactiveValue<SourceType[Name]> {
const child = ReactiveValue.fromInitialValue(sourceValue.get()[propertyName]);
const childRef = (window as any).WeakRef
? new (window as any).WeakRef(child)
: { deref: () => child };
const childRef = typeof WeakRef !== 'undefined' ? new WeakRef(child) : { deref: () => child };

// When the source is updated...
const sourceListener = sourceValue.onUpdate((newValue) => {
Expand Down

1 comment on commit b4a3987

@personalizedrefrigerator
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The commit title should read:

fix: Fix feature test for WeakRef fails in browser extensions (#97)

Please sign in to comment.