Skip to content

Commit 4a85034

Browse files
committed
Manage destruction with symbol-properties, rather than weakmap
1 parent f4f8b5d commit 4a85034

2 files changed

Lines changed: 10 additions & 17 deletions

File tree

packages/@glimmer/component/src/-private/component.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import { DEBUG } from '@glimmer/env';
22

3-
const DESTROYING = new WeakMap<GlimmerComponent<object>, boolean>();
4-
const DESTROYED = new WeakMap<GlimmerComponent<object>, boolean>();
5-
6-
export function setDestroying(component: GlimmerComponent<object>): void {
7-
DESTROYING.set(component, true);
8-
}
9-
export function setDestroyed(component: GlimmerComponent<object>): void {
10-
DESTROYED.set(component, true);
11-
}
3+
export const IS_DESTROYING_KEY = Symbol('__is_destroying__');
4+
export const IS_DESTROYED_KEY = Symbol('__is_destroyed__');
125

136
// This provides a type-safe `WeakMap`: the getter and setter link the key to a
147
// specific value. This is how `WeakMap`s actually behave, but the TS type
@@ -224,6 +217,9 @@ export type Args<S> = ExpandSignature<S>['Args']['Named'];
224217
* inside the component `this.args.firstName` would also be `Tom`.
225218
*/
226219
export default class GlimmerComponent<S = unknown> {
220+
[IS_DESTROYING_KEY] = false;
221+
[IS_DESTROYED_KEY] = false;
222+
227223
/**
228224
* Constructs a new component and assigns itself the passed properties. You
229225
* should not construct new components yourself. Instead, Glimmer will
@@ -240,9 +236,6 @@ export default class GlimmerComponent<S = unknown> {
240236
}
241237

242238
this.args = args;
243-
244-
DESTROYING.set(this, false);
245-
DESTROYED.set(this, false);
246239
}
247240

248241
/**
@@ -272,11 +265,11 @@ export default class GlimmerComponent<S = unknown> {
272265
readonly args: Readonly<Args<S>>;
273266

274267
get isDestroying(): boolean {
275-
return DESTROYING.get(this) || false;
268+
return this[IS_DESTROYING_KEY] || false;
276269
}
277270

278271
get isDestroyed(): boolean {
279-
return DESTROYED.get(this) || false;
272+
return this[IS_DESTROYED_KEY] || false;
280273
}
281274

282275
/**

packages/@glimmer/component/src/-private/ember-component-manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { capabilities } from '@ember/component';
33
import { schedule } from '@ember/runloop';
44
import BaseComponentManager from './base-component-manager';
55

6-
import { type default as GlimmerComponent, setDestroyed, setDestroying } from './component';
6+
import { type default as GlimmerComponent, IS_DESTROYING_KEY, IS_DESTROYED_KEY } from './component';
77
import type { Arguments } from '@glimmer/interfaces';
88

99
const CAPABILITIES = capabilities('3.13', {
@@ -18,7 +18,7 @@ function scheduledDestroyComponent(component: GlimmerComponent): void {
1818
}
1919

2020
destroy(component);
21-
setDestroyed(component);
21+
component[IS_DESTROYED_KEY] = true;
2222
}
2323

2424
/**
@@ -35,7 +35,7 @@ class EmberGlimmerComponentManager extends BaseComponentManager<GlimmerComponent
3535
return;
3636
}
3737

38-
setDestroying(component);
38+
component[IS_DESTROYING_KEY] = true;
3939

4040
schedule('actions', component, component.willDestroy);
4141
schedule('destroy', this, scheduledDestroyComponent, component);

0 commit comments

Comments
 (0)