Skip to content

Commit c049312

Browse files
authored
Polyfill Symbol.dispose and Symbol.asyncDispose (#828)
* Make sure `Symbol.dispose` and `Symbol.asyncDispose` are defined before usage * Change * Update comment * Use example from typescript docs
1 parent 5077a9c commit c049312

28 files changed

+72
-0
lines changed

.changeset/silver-ears-change.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@itwin/presentation-hierarchies-react": patch
3+
"@itwin/unified-selection": patch
4+
"@itwin/presentation-hierarchies": patch
5+
"@itwin/presentation-components": patch
6+
---
7+
8+
Polyfill `Symbol.dispose` and `Symbol.asyncDispose` to make sure that code using the upcoming JS recource management API works in all environments.

packages/components/src/presentation-components/common/ContentDataProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @module Core
77
*/
88

9+
import "./DisposePolyfill.js";
910
import { PropertyDescription, PropertyRecord } from "@itwin/appui-abstract";
1011
import { Logger } from "@itwin/core-bentley";
1112
import { IModelApp, IModelConnection } from "@itwin/core-frontend";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
/**
7+
* Polyfill for upcoming resource management feature: https://github.com/tc39/proposal-explicit-resource-management
8+
*/
9+
(Symbol as any).dispose ??= Symbol("Symbol.dispose");
10+
(Symbol as any).asyncDispose ??= Symbol("Symbol.asyncDispose");

packages/components/src/presentation-components/common/IPresentationDataProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @module Core
77
*/
88

9+
import "./DisposePolyfill.js";
910
import { IModelConnection } from "@itwin/core-frontend";
1011

1112
/**

packages/components/src/presentation-components/common/RulesetRegistrationHelper.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @module Core
77
*/
88

9+
import "./DisposePolyfill.js";
910
import { RegisteredRuleset, Ruleset } from "@itwin/presentation-common";
1011
import { Presentation } from "@itwin/presentation-frontend";
1112

packages/components/src/presentation-components/common/Utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @module Core
77
*/
88

9+
import "../common/DisposePolyfill.js";
910
import * as mm from "micro-memoize";
1011
import { LegacyRef, MutableRefObject, RefCallback, useCallback, useEffect, useState } from "react";
1112
import { Primitives, PrimitiveValue, PropertyDescription, PropertyRecord, PropertyValueFormat } from "@itwin/appui-abstract";

packages/components/src/presentation-components/properties/inputs/ItemsLoader.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "../../common/DisposePolyfill.js";
7+
68
/** @internal */
79
export const VALUE_BATCH_SIZE = 100;
810

packages/components/src/presentation-components/properties/inputs/UseNavigationPropertyTargetsLoader.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @module Internal
77
*/
88

9+
import "../../common/DisposePolyfill.js";
910
import { useEffect, useMemo, useState } from "react";
1011
import { EMPTY, from, map, mergeMap, toArray } from "rxjs";
1112
import { PropertyDescription } from "@itwin/appui-abstract";

packages/components/src/presentation-components/properties/inputs/UseUniquePropertyValuesLoader.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "../../common/DisposePolyfill.js";
67
import { useEffect, useMemo, useState } from "react";
78
import { from, map, mergeMap, toArray } from "rxjs";
89
import { IModelConnection } from "@itwin/core-frontend";

packages/components/src/presentation-components/propertygrid/DataProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @module PropertyGrid
77
*/
88

9+
import "../common/DisposePolyfill.js";
910
import { inPlaceSort } from "fast-sort";
1011
import { PropertyRecord, PropertyValueFormat as UiPropertyValueFormat } from "@itwin/appui-abstract";
1112
import { IPropertyDataProvider, PropertyCategory, PropertyData, PropertyDataChangeEvent } from "@itwin/components-react";

packages/components/src/presentation-components/tree/DataProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @module Tree
88
*/
99

10+
import "../common/DisposePolyfill.js";
1011
import { DelayLoadedTreeNodeItem, PageOptions, PropertyFilterRuleGroupOperator, TreeNodeItem } from "@itwin/components-react";
1112
import { Logger } from "@itwin/core-bentley";
1213
import { IModelConnection } from "@itwin/core-frontend";

packages/components/src/presentation-components/tree/FilteredDataProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55
/* eslint-disable @typescript-eslint/no-deprecated */
66

7+
import "../common/DisposePolyfill.js";
78
import {
89
ActiveMatchInfo,
910
DelayLoadedTreeNodeItem,

packages/components/src/presentation-components/tree/controlled/TreeHooks.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @module Tree
88
*/
99

10+
import "../../common/DisposePolyfill.js";
1011
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
1112
import { Subscription } from "rxjs/internal/Subscription";
1213
import {

packages/components/src/presentation-components/tree/controlled/UsePresentationTreeState.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @module Tree
88
*/
99

10+
import "../../common/DisposePolyfill.js";
1011
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
1112
import {
1213
AbstractTreeNodeLoaderWithProvider,

packages/components/src/presentation-components/tree/controlled/UseUnifiedSelection.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @module Tree
88
*/
99

10+
import "../../common/DisposePolyfill.js";
1011
import { useCallback } from "react";
1112
import { Subject, takeUntil, tap } from "rxjs";
1213
import {

packages/components/src/presentation-components/viewport/ViewportSelectionHandler.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "../common/DisposePolyfill.js";
67
import { from, Subject, takeUntil } from "rxjs";
78
import { using } from "@itwin/core-bentley";
89
import { IModelConnection } from "@itwin/core-frontend";

packages/components/src/presentation-components/viewport/WithUnifiedSelection.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @module Viewport
77
*/
88

9+
import "../common/DisposePolyfill.js";
910
import { createContext, memo, PropsWithChildren, useContext, useEffect, useState } from "react";
1011
import { ViewportProps } from "@itwin/imodel-components-react";
1112
import { getDisplayName } from "../common/Utils.js";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
/**
7+
* Polyfill for upcoming resource management feature: https://github.com/tc39/proposal-explicit-resource-management
8+
*/
9+
(Symbol as any).dispose ??= Symbol("Symbol.dispose");
10+
(Symbol as any).asyncDispose ??= Symbol("Symbol.asyncDispose");

packages/hierarchies-react/src/presentation-hierarchies-react/internal/TreeActions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "./DisposePolyfill.js";
67
import { Draft, enableMapSet, produce } from "immer";
78
import { EMPTY, Observable, reduce, Subject, takeUntil } from "rxjs";
89
import { GenericInstanceFilter, HierarchyNode, HierarchyProvider } from "@itwin/presentation-hierarchies";

packages/hierarchies-react/src/presentation-hierarchies-react/internal/Utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "./DisposePolyfill.js";
67
import { HierarchyNode, HierarchyNodeKey } from "@itwin/presentation-hierarchies";
78

89
/** @internal */

packages/hierarchies/src/hierarchies/HierarchyProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "./internal/DisposePolyfill.js";
67
import { filter, first, from, map, mergeMap, of } from "rxjs";
78
import { BeEvent } from "@itwin/core-bentley";
89
import { GenericInstanceFilter } from "@itwin/core-common";

packages/hierarchies/src/hierarchies/imodel/IModelHierarchyProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "../internal/DisposePolyfill.js";
67
import {
78
catchError,
89
concat,

packages/hierarchies/src/hierarchies/internal/Common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "./DisposePolyfill.js";
67
import naturalCompare from "natural-compare-lite";
78
import { ConcatenatedValue } from "@itwin/presentation-shared";
89
import { HierarchyNodeKey } from "../HierarchyNodeKey.js";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
/**
7+
* Polyfill for upcoming resource management feature: https://github.com/tc39/proposal-explicit-resource-management
8+
*/
9+
(Symbol as any).dispose ??= Symbol("Symbol.dispose");
10+
(Symbol as any).asyncDispose ??= Symbol("Symbol.asyncDispose");

packages/unified-selection/src/unified-selection/CachingHiliteSetProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "./DisposePolyfill.js";
67
import { from, Observable, shareReplay } from "rxjs";
78
import { eachValueFrom } from "rxjs-for-await";
89
import { ECClassHierarchyInspector, ECSqlQueryExecutor } from "@itwin/presentation-shared";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
/**
7+
* Polyfill for upcoming resource management feature: https://github.com/tc39/proposal-explicit-resource-management
8+
*/
9+
(Symbol as any).dispose ??= Symbol("Symbol.dispose");
10+
(Symbol as any).asyncDispose ??= Symbol("Symbol.asyncDispose");

packages/unified-selection/src/unified-selection/EnableUnifiedSelectionSyncWithIModel.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "./DisposePolyfill.js";
67
import { EMPTY, firstValueFrom, from, map, merge, Observable, Subject, takeUntil, toArray } from "rxjs";
78
import { ECClassHierarchyInspector, ECSqlQueryExecutor } from "@itwin/presentation-shared";
89
import { CachingHiliteSetProvider, createCachingHiliteSetProvider } from "./CachingHiliteSetProvider.js";

packages/unified-selection/src/unified-selection/Utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import "./DisposePolyfill.js";
67
import { bufferCount, concatAll, concatMap, delay, Observable, of } from "rxjs";
78
import { createMainThreadReleaseOnTimePassedHandler, ECSqlBinding, ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryRow } from "@itwin/presentation-shared";
89

0 commit comments

Comments
 (0)