Skip to content

Commit

Permalink
Polyfill Symbol.dispose and Symbol.asyncDispose (#828)
Browse files Browse the repository at this point in the history
* Make sure `Symbol.dispose` and `Symbol.asyncDispose` are defined before usage

* Change

* Update comment

* Use example from typescript docs
  • Loading branch information
saskliutas authored Jan 7, 2025
1 parent 5077a9c commit c049312
Show file tree
Hide file tree
Showing 28 changed files with 72 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/silver-ears-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@itwin/presentation-hierarchies-react": patch
"@itwin/unified-selection": patch
"@itwin/presentation-hierarchies": patch
"@itwin/presentation-components": patch
---

Polyfill `Symbol.dispose` and `Symbol.asyncDispose` to make sure that code using the upcoming JS recource management API works in all environments.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @module Core
*/

import "./DisposePolyfill.js";
import { PropertyDescription, PropertyRecord } from "@itwin/appui-abstract";
import { Logger } from "@itwin/core-bentley";
import { IModelApp, IModelConnection } from "@itwin/core-frontend";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

/**
* Polyfill for upcoming resource management feature: https://github.com/tc39/proposal-explicit-resource-management
*/
(Symbol as any).dispose ??= Symbol("Symbol.dispose");
(Symbol as any).asyncDispose ??= Symbol("Symbol.asyncDispose");
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @module Core
*/

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @module Core
*/

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @module Core
*/

import "../common/DisposePolyfill.js";
import * as mm from "micro-memoize";
import { LegacyRef, MutableRefObject, RefCallback, useCallback, useEffect, useState } from "react";
import { Primitives, PrimitiveValue, PropertyDescription, PropertyRecord, PropertyValueFormat } from "@itwin/appui-abstract";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import "../../common/DisposePolyfill.js";

/** @internal */
export const VALUE_BATCH_SIZE = 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @module Internal
*/

import "../../common/DisposePolyfill.js";
import { useEffect, useMemo, useState } from "react";
import { EMPTY, from, map, mergeMap, toArray } from "rxjs";
import { PropertyDescription } from "@itwin/appui-abstract";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import "../../common/DisposePolyfill.js";
import { useEffect, useMemo, useState } from "react";
import { from, map, mergeMap, toArray } from "rxjs";
import { IModelConnection } from "@itwin/core-frontend";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @module PropertyGrid
*/

import "../common/DisposePolyfill.js";
import { inPlaceSort } from "fast-sort";
import { PropertyRecord, PropertyValueFormat as UiPropertyValueFormat } from "@itwin/appui-abstract";
import { IPropertyDataProvider, PropertyCategory, PropertyData, PropertyDataChangeEvent } from "@itwin/components-react";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @module Tree
*/

import "../common/DisposePolyfill.js";
import { DelayLoadedTreeNodeItem, PageOptions, PropertyFilterRuleGroupOperator, TreeNodeItem } from "@itwin/components-react";
import { Logger } from "@itwin/core-bentley";
import { IModelConnection } from "@itwin/core-frontend";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
/* eslint-disable @typescript-eslint/no-deprecated */

import "../common/DisposePolyfill.js";
import {
ActiveMatchInfo,
DelayLoadedTreeNodeItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @module Tree
*/

import "../../common/DisposePolyfill.js";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Subscription } from "rxjs/internal/Subscription";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @module Tree
*/

import "../../common/DisposePolyfill.js";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import {
AbstractTreeNodeLoaderWithProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @module Tree
*/

import "../../common/DisposePolyfill.js";
import { useCallback } from "react";
import { Subject, takeUntil, tap } from "rxjs";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import "../common/DisposePolyfill.js";
import { from, Subject, takeUntil } from "rxjs";
import { using } from "@itwin/core-bentley";
import { IModelConnection } from "@itwin/core-frontend";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @module Viewport
*/

import "../common/DisposePolyfill.js";
import { createContext, memo, PropsWithChildren, useContext, useEffect, useState } from "react";
import { ViewportProps } from "@itwin/imodel-components-react";
import { getDisplayName } from "../common/Utils.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

/**
* Polyfill for upcoming resource management feature: https://github.com/tc39/proposal-explicit-resource-management
*/
(Symbol as any).dispose ??= Symbol("Symbol.dispose");
(Symbol as any).asyncDispose ??= Symbol("Symbol.asyncDispose");
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import "./DisposePolyfill.js";
import { Draft, enableMapSet, produce } from "immer";
import { EMPTY, Observable, reduce, Subject, takeUntil } from "rxjs";
import { GenericInstanceFilter, HierarchyNode, HierarchyProvider } from "@itwin/presentation-hierarchies";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

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

/** @internal */
Expand Down
1 change: 1 addition & 0 deletions packages/hierarchies/src/hierarchies/HierarchyProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import "./internal/DisposePolyfill.js";
import { filter, first, from, map, mergeMap, of } from "rxjs";
import { BeEvent } from "@itwin/core-bentley";
import { GenericInstanceFilter } from "@itwin/core-common";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import "../internal/DisposePolyfill.js";
import {
catchError,
concat,
Expand Down
1 change: 1 addition & 0 deletions packages/hierarchies/src/hierarchies/internal/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import "./DisposePolyfill.js";
import naturalCompare from "natural-compare-lite";
import { ConcatenatedValue } from "@itwin/presentation-shared";
import { HierarchyNodeKey } from "../HierarchyNodeKey.js";
Expand Down
10 changes: 10 additions & 0 deletions packages/hierarchies/src/hierarchies/internal/DisposePolyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

/**
* Polyfill for upcoming resource management feature: https://github.com/tc39/proposal-explicit-resource-management
*/
(Symbol as any).dispose ??= Symbol("Symbol.dispose");
(Symbol as any).asyncDispose ??= Symbol("Symbol.asyncDispose");
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import "./DisposePolyfill.js";
import { from, Observable, shareReplay } from "rxjs";
import { eachValueFrom } from "rxjs-for-await";
import { ECClassHierarchyInspector, ECSqlQueryExecutor } from "@itwin/presentation-shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

/**
* Polyfill for upcoming resource management feature: https://github.com/tc39/proposal-explicit-resource-management
*/
(Symbol as any).dispose ??= Symbol("Symbol.dispose");
(Symbol as any).asyncDispose ??= Symbol("Symbol.asyncDispose");
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import "./DisposePolyfill.js";
import { EMPTY, firstValueFrom, from, map, merge, Observable, Subject, takeUntil, toArray } from "rxjs";
import { ECClassHierarchyInspector, ECSqlQueryExecutor } from "@itwin/presentation-shared";
import { CachingHiliteSetProvider, createCachingHiliteSetProvider } from "./CachingHiliteSetProvider.js";
Expand Down
1 change: 1 addition & 0 deletions packages/unified-selection/src/unified-selection/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

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

Expand Down

0 comments on commit c049312

Please sign in to comment.