Skip to content

Commit b92b228

Browse files
committed
Simplify
1 parent 71a716e commit b92b228

8 files changed

Lines changed: 25 additions & 35 deletions

File tree

‎packages/@glimmer/destroyable/index.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type { Destroyable, Destructor } from '@glimmer/interfaces';
33
import debugToString from '@glimmer/debug-util/lib/debug-to-string';
44
import { scheduleDestroy, scheduleDestroyed } from '@glimmer/global-context';
55
import {
6-
DESTROYABLE_META_SLOT,
6+
DESTROYABLE_META_KEY,
77
type HasDestroyableMetaSlot,
8-
} from '@glimmer/util/lib/destroyable-slot';
8+
} from '@glimmer/util/lib/destroyable-key';
99

1010
const LIVE_STATE = 0;
1111
const DESTROYING_STATE = 1;
@@ -100,15 +100,15 @@ function createMeta<T extends Destroyable>(destroyable: T): DestroyableMeta<T> {
100100

101101
function getDestroyableMeta<T extends Destroyable>(destroyable: T): DestroyableMeta<T> {
102102
let slotted = destroyable as HasDestroyableMetaSlot;
103-
let own = slotted[DESTROYABLE_META_SLOT];
103+
let own = slotted[DESTROYABLE_META_KEY];
104104

105105
if (own !== undefined) return own as DestroyableMeta<T>;
106106

107107
// `in` rather than a write, so this stays a read for everything else.
108-
if (DESTROYABLE_META_SLOT in slotted) {
108+
if (DESTROYABLE_META_KEY in slotted) {
109109
let meta = createMeta(destroyable);
110110

111-
slotted[DESTROYABLE_META_SLOT] = meta;
111+
slotted[DESTROYABLE_META_KEY] = meta;
112112

113113
if (DEBUG && DESTROYABLE_META instanceof Map) {
114114
DESTROYABLE_META.set(destroyable, meta as unknown as DestroyableMeta<Destroyable>);
@@ -239,12 +239,12 @@ export function destroyChildren(destroyable: Destroyable) {
239239
/** Meta if there is any, without creating it. Mirrors `getDestroyableMeta`. */
240240
function peekDestroyableMeta(destroyable: Destroyable): DestroyableMeta<Destroyable> | undefined {
241241
let slotted = destroyable as HasDestroyableMetaSlot;
242-
let own = slotted[DESTROYABLE_META_SLOT];
242+
let own = slotted[DESTROYABLE_META_KEY];
243243

244244
if (own !== undefined) return own as DestroyableMeta<Destroyable>;
245245

246246
// An empty slot is proof there is no meta, so the map can be skipped.
247-
if (DESTROYABLE_META_SLOT in slotted) return undefined;
247+
if (DESTROYABLE_META_KEY in slotted) return undefined;
248248

249249
return DESTROYABLE_META.get(destroyable);
250250
}

‎packages/@glimmer/reference/lib/reference.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
import type { Revision } from '@glimmer/validator/lib/validators';
1313
import type { Tag } from '@glimmer/interfaces';
1414
import { expect } from '@glimmer/debug-util/lib/platform-utils';
15-
import { DESTROYABLE_META_SLOT } from '@glimmer/util/lib/destroyable-slot';
15+
import { DESTROYABLE_META_KEY } from '@glimmer/util/lib/destroyable-key';
1616
import { getProp, setProp } from '@glimmer/global-context';
1717
import { isDict } from '@glimmer/util/lib/collections';
1818
import { CONSTANT_TAG, INITIAL, validateTag, valueForTag } from '@glimmer/validator/lib/validators';
@@ -36,8 +36,7 @@ export interface ReferenceEnvironment {
3636
}
3737

3838
class ReferenceImpl<T = unknown> implements Reference<T> {
39-
declare [DESTROYABLE_META_SLOT]: object | undefined;
40-
39+
[DESTROYABLE_META_KEY]: object | undefined;
4140
[REFERENCE]: ReferenceType;
4241
public tag: Nullable<Tag> = null;
4342
public lastRevision: Revision = INITIAL;
@@ -52,7 +51,6 @@ class ReferenceImpl<T = unknown> implements Reference<T> {
5251

5352
constructor(type: ReferenceType) {
5453
this[REFERENCE] = type;
55-
this[DESTROYABLE_META_SLOT] = undefined;
5654
}
5755
}
5856

‎packages/@glimmer/runtime/lib/vm/append.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type { MachineRegister, Register, SyscallRegister } from '@glimmer/vm/lib
2626
import { dev, expect } from '@glimmer/debug-util/lib/platform-utils';
2727
import { unwrapHandle } from '@glimmer/debug-util/lib/template';
2828
import { associateDestroyableChild } from '@glimmer/destroyable';
29-
import { DESTROYABLE_META_SLOT } from '@glimmer/util/lib/destroyable-slot';
29+
import { DESTROYABLE_META_KEY } from '@glimmer/util/lib/destroyable-key';
3030
import { assertGlobalContextWasSet } from '@glimmer/global-context';
3131
import { LOCAL_DEBUG, LOCAL_TRACE_LOGGING } from '@glimmer/local-debug-flags';
3232
import { createIteratorItemRef } from '@glimmer/reference/lib/iterable';
@@ -55,13 +55,13 @@ import RenderResultImpl from './render-result';
5555
import EvaluationStackImpl from './stack';
5656
import { ListBlockOpcode, ListItemOpcode, TryOpcode } from './update';
5757

58-
/** The VM's own root destroyable, on the fast path like the block opcodes. */
58+
/*
59+
* The VM's own root destroyable, on the fast path like the block opcodes.
60+
*
61+
* Introduction and background in https://github.com/emberjs/ember.js/pull/21571
62+
*/
5963
class Drop {
60-
declare [DESTROYABLE_META_SLOT]: object | undefined;
61-
62-
constructor() {
63-
this[DESTROYABLE_META_SLOT] = undefined;
64-
}
64+
[DESTROYABLE_META_KEY]: object | undefined;
6565
}
6666

6767
class Stacks {

‎packages/@glimmer/runtime/lib/vm/element-builder.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { expect } from '@glimmer/debug-util/lib/platform-utils';
2222
import assert from '@glimmer/debug-util/lib/assert';
2323
import { setLocalDebugType } from '@glimmer/debug-util/lib/debug-brand';
2424
import { destroy, registerDestructor } from '@glimmer/destroyable';
25-
import { DESTROYABLE_META_SLOT } from '@glimmer/util/lib/destroyable-slot';
25+
import { DESTROYABLE_META_KEY } from '@glimmer/util/lib/destroyable-key';
2626
import { LOCAL_DEBUG } from '@glimmer/local-debug-flags';
2727
import { StackImpl as Stack } from '@glimmer/util/lib/collections';
2828

@@ -398,15 +398,14 @@ export class NewTreeBuilder implements TreeBuilder {
398398

399399
export class AppendingBlockImpl implements AppendingBlock {
400400
declare debug?: { first: () => Nullable<SimpleNode>; last: () => Nullable<SimpleNode> };
401-
declare [DESTROYABLE_META_SLOT]: object | undefined;
401+
402+
[DESTROYABLE_META_KEY]: object | undefined;
402403

403404
protected first: Nullable<FirstNode> = null;
404405
protected last: Nullable<LastNode> = null;
405406
protected nesting = 0;
406407

407408
constructor(private parent: SimpleElement) {
408-
this[DESTROYABLE_META_SLOT] = undefined;
409-
410409
setLocalDebugType('block:simple', this);
411410

412411
if (LOCAL_DEBUG) {

‎packages/@glimmer/runtime/lib/vm/render-result.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,20 @@ import type {
88
} from '@glimmer/interfaces';
99
import { unreachable } from '@glimmer/debug-util/lib/platform-utils';
1010
import { associateDestroyableChild, registerDestructor } from '@glimmer/destroyable';
11-
import { DESTROYABLE_META_SLOT } from '@glimmer/util/lib/destroyable-slot';
11+
import { DESTROYABLE_META_KEY } from '@glimmer/util/lib/destroyable-key';
1212

1313
import { clear } from '../bounds';
1414
import { UpdatingVM } from './update';
1515

1616
export default class RenderResultImpl implements RenderResult {
17-
declare [DESTROYABLE_META_SLOT]: object | undefined;
17+
[DESTROYABLE_META_KEY]: object | undefined;
1818

1919
constructor(
2020
public env: Environment,
2121
private updating: UpdatingOpcode[],
2222
private bounds: AppendingBlock,
2323
readonly drop: object
2424
) {
25-
this[DESTROYABLE_META_SLOT] = undefined;
26-
2725
associateDestroyableChild(this, drop);
2826
registerDestructor(this, () => clear(this.bounds));
2927
}

‎packages/@glimmer/runtime/lib/vm/update.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type { OpaqueIterationItem, OpaqueIterator } from '@glimmer/reference/lib
1818
import type { Reference } from '@glimmer/reference/lib/reference';
1919
import { expect, unwrap } from '@glimmer/debug-util/lib/platform-utils';
2020
import { associateDestroyableChild, destroy, destroyChildren } from '@glimmer/destroyable';
21-
import { DESTROYABLE_META_SLOT } from '@glimmer/util/lib/destroyable-slot';
21+
import { DESTROYABLE_META_KEY } from '@glimmer/util/lib/destroyable-key';
2222
import { LOCAL_DEBUG } from '@glimmer/local-debug-flags';
2323
import { updateRef, valueForRef } from '@glimmer/reference/lib/reference';
2424
import { logStep } from '@glimmer/util/lib/debug-steps';
@@ -112,9 +112,7 @@ export interface VMState {
112112
}
113113

114114
export abstract class BlockOpcode implements UpdatingOpcode, Bounds {
115-
// Declaring the slot is what opts these into the fast path in
116-
// `@glimmer/destroyable`. One of these exists per `{{#each}}` item.
117-
declare [DESTROYABLE_META_SLOT]: object | undefined;
115+
[DESTROYABLE_META_KEY]: object | undefined;
118116

119117
public children: UpdatingOpcode[];
120118

@@ -128,7 +126,6 @@ export abstract class BlockOpcode implements UpdatingOpcode, Bounds {
128126
) {
129127
this.children = children;
130128
this.bounds = bounds;
131-
this[DESTROYABLE_META_SLOT] = undefined;
132129
}
133130

134131
parentElement() {

‎packages/@glimmer/util/index.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,3 @@ export function assertNever(value: never, desc = 'unexpected unreachable branch'
2121

2222
throw new Error(`code reached unreachable`);
2323
}
24-
export { DESTROYABLE_META_SLOT } from './lib/destroyable-slot';
25-
export type { HasDestroyableMetaSlot } from './lib/destroyable-slot';

packages/@glimmer/util/lib/destroyable-slot.ts renamed to packages/@glimmer/util/lib/destroyable-key.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* Never write this onto an object Glimmer did not construct. Destroyables are
88
* public through `@ember/destroyable` and can be any object a user hands in.
99
*/
10-
export const DESTROYABLE_META_SLOT = Symbol('DESTROYABLE_META_SLOT');
10+
export const DESTROYABLE_META_KEY = Symbol('__destroyable_meta__');
1111

1212
export interface HasDestroyableMetaSlot {
13-
[DESTROYABLE_META_SLOT]?: object | undefined;
13+
[DESTROYABLE_META_KEY]?: object | undefined;
1414
}

0 commit comments

Comments
 (0)