Skip to content

Commit fb93a26

Browse files
authored
Remove AbortScope utility class (#139)
1 parent e96c133 commit fb93a26

4 files changed

Lines changed: 10 additions & 42 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
3030
- Preparations to extract generic scrollable paper component `Paper` from diagram-specific state and logic:
3131
* Replace `reactodia-paper-area` CSS class by `reactodia-canvas-area` and `reactodia-paper`.
3232
* Deprecate `CanvasMetrics.area` in favor of `CanvasMetrics.pane`.
33+
- Remove `AbortScope` utility class (can be trivially replaced by the built-in [`AbortSignal.any()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static) function).
3334

3435
## [0.33.0] - 2026-03-16
3536
#### 🚀 New Features

src/coreUtils/async.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,6 @@ export function mapAbortedToNull<T>(
1919
return promise.then(onResolve, onReject);
2020
}
2121

22-
/**
23-
* Creates a derived abort signal, i.e. `AbortSignal` instance
24-
* which is automatically aborted when parent signal is aborted,
25-
* but can be aborted separately the same way as normal `AbortController`.
26-
*
27-
* @category Utilities
28-
*/
29-
export class AbortScope {
30-
private readonly controller: AbortController;
31-
private readonly parentSignal: AbortSignal | undefined;
32-
private onAbort: (() => void) | undefined;
33-
34-
constructor(parentSignal: AbortSignal | undefined) {
35-
this.controller = new AbortController();
36-
if (parentSignal) {
37-
this.parentSignal = undefined;
38-
this.onAbort = () => this.controller.abort();
39-
parentSignal.addEventListener('abort', this.onAbort);
40-
}
41-
}
42-
43-
get signal(): AbortSignal {
44-
return this.controller.signal;
45-
}
46-
47-
[Symbol.dispose]() {
48-
this.controller.abort();
49-
if (this.parentSignal && this.onAbort) {
50-
this.parentSignal.removeEventListener('abort', this.onAbort);
51-
}
52-
}
53-
54-
abort() {
55-
this[Symbol.dispose]();
56-
}
57-
}
58-
5922
/**
6023
* Waits a specified timeout in milliseconds the resolves the result promise.
6124
*

src/editor/dataDiagramModel.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ReadonlyHashMap } from '@reactodia/hashmap';
22

3-
import { AbortScope } from '../coreUtils/async';
43
import { AnyEvent, EventSource, Events } from '../coreUtils/events';
54
import { Translation, TranslatedText } from '../coreUtils/i18n';
65

@@ -157,7 +156,7 @@ export class DataDiagramModel extends DiagramModel implements DataGraphStructure
157156
private readonly translation: Translation;
158157

159158
private dataGraph = new DataGraph();
160-
private loadingScope: AbortScope | undefined;
159+
private loadingScope: AbortController | undefined;
161160
private _dataProvider: DataProvider;
162161
private _locale: DataLocaleProvider;
163162
private fetcher: DataFetcher;
@@ -390,11 +389,15 @@ export class DataDiagramModel extends DiagramModel implements DataGraphStructure
390389
translation: this.translation,
391390
});
392391

393-
this.loadingScope = new AbortScope(parentSignal);
392+
const scope = new AbortController();
393+
this.loadingScope = scope;
394+
const onParentSignalAbort = () => scope.abort();
395+
394396
this.extendedSource.trigger('loadingStart', {source: this});
395397
const signal = this.loadingScope.signal;
396-
398+
397399
try {
400+
parentSignal?.addEventListener('abort', onParentSignalAbort);
398401
signal.throwIfAborted();
399402

400403
this.setLinkSettings(diagram.linkTypeOptions ?? []);
@@ -438,6 +441,7 @@ export class DataDiagramModel extends DiagramModel implements DataGraphStructure
438441
this.extendedSource.trigger('loadingError', {source: this, error});
439442
throw new Error('Reactodia: failed to import a layout', {cause: error});
440443
} finally {
444+
parentSignal?.removeEventListener('abort', onParentSignalAbort);
441445
this.loadingScope?.abort();
442446
this.loadingScope = undefined;
443447
}

src/workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import '../styles/main.scss';
22

3-
export { AbortScope, mapAbortedToNull, delay } from './coreUtils/async';
3+
export { mapAbortedToNull, delay } from './coreUtils/async';
44
export { moveComparator, shallowArrayEqual } from './coreUtils/collections';
55
export { useColorScheme } from './coreUtils/colorScheme';
66
export {

0 commit comments

Comments
 (0)