Skip to content

Commit

Permalink
First-pass/spike at absorbing the changes on the error-recovery branch
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode committed Dec 13, 2023
1 parent af5528c commit 2d8a515
Show file tree
Hide file tree
Showing 26 changed files with 224 additions and 201 deletions.
36 changes: 21 additions & 15 deletions packages/@ember/-internals/glimmer/lib/component-managers/curly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ import type {
WithDynamicLayout,
WithDynamicTagName,
} from '@glimmer/interfaces';
import type { Reference } from '@glimmer/reference';
import { childRefFor, createComputeRef, createPrimitiveRef, valueForRef } from '@glimmer/reference';
import type { Reactive } from '@glimmer/reference';

Check failure on line 28 in packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Module '"@glimmer/reference"' has no exported member 'Reactive'.

Check failure on line 28 in packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Module '"@glimmer/reference"' has no exported member 'Reactive'.
import {
Formula,

Check failure on line 30 in packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Module '"@glimmer/reference"' has no exported member 'Formula'.

Check failure on line 30 in packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Module '"@glimmer/reference"' has no exported member 'Formula'.
getReactiveProperty,

Check failure on line 31 in packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Module '"@glimmer/reference"' has no exported member 'getReactiveProperty'.

Check failure on line 31 in packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Module '"@glimmer/reference"' has no exported member 'getReactiveProperty'.
createPrimitiveCell,

Check failure on line 32 in packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

'"@glimmer/reference"' has no exported member named 'createPrimitiveCell'. Did you mean 'createPrimitiveRef'?

Check failure on line 32 in packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

'"@glimmer/reference"' has no exported member named 'createPrimitiveCell'. Did you mean 'createPrimitiveRef'?
unwrapReactive,

Check failure on line 33 in packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Module '"@glimmer/reference"' has no exported member 'unwrapReactive'.

Check failure on line 33 in packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Module '"@glimmer/reference"' has no exported member 'unwrapReactive'.
} from '@glimmer/reference';
import { reifyPositional } from '@glimmer/runtime';
import { EMPTY_ARRAY, unwrapTemplate } from '@glimmer/util';
import {
Expand Down Expand Up @@ -59,7 +64,7 @@ export const DIRTY_TAG = Symbol('DIRTY_TAG');
export const IS_DISPATCHING_ATTRS = Symbol('IS_DISPATCHING_ATTRS');
export const BOUNDS = Symbol('BOUNDS');

const EMBER_VIEW_REF = createPrimitiveRef('ember-view');
const EMBER_VIEW_REF = createPrimitiveCell('ember-view');

function aliasIdToElementId(args: VMArguments, props: any) {
if (args.named.has('id')) {
Expand All @@ -77,7 +82,7 @@ function aliasIdToElementId(args: VMArguments, props: any) {
function applyAttributeBindings(
attributeBindings: Array<string>,
component: Component,
rootRef: Reference<Component>,
rootRef: Reactive<Component>,
operations: ElementOperations
) {
let seen: string[] = [];
Expand All @@ -99,11 +104,11 @@ function applyAttributeBindings(

if (seen.indexOf('id') === -1) {
let id = component.elementId ? component.elementId : guidFor(component);
operations.setAttribute('id', createPrimitiveRef(id), false, null);
operations.setAttribute('id', createPrimitiveCell(id), false, null);
}
}

const EMPTY_POSITIONAL_ARGS: Reference[] = [];
const EMPTY_POSITIONAL_ARGS: Reactive[] = [];

debugFreeze(EMPTY_POSITIONAL_ARGS);

Expand Down Expand Up @@ -179,7 +184,7 @@ export default class CurlyComponentManager
assert('[BUG] unexpectedly missing __ARGS__ after check', __ARGS__);

// does this need to be untracked?
let __args__ = valueForRef(__ARGS__) as CapturedArguments;
let __args__ = unwrapReactive(__ARGS__) as CapturedArguments;

let prepared = {
positional: __args__.positional,
Expand Down Expand Up @@ -209,7 +214,7 @@ export default class CurlyComponentManager
);
let captured = args.positional.capture();
named = {
[positionalParams]: createComputeRef(() => reifyPositional(captured)),
[positionalParams]: Formula(() => reifyPositional(captured)),
};
Object.assign(named, args.named.capture());
} else if (Array.isArray(positionalParams) && positionalParams.length > 0) {
Expand All @@ -232,7 +237,7 @@ export default class CurlyComponentManager
return null;
}

return { positional: EMPTY_ARRAY as readonly Reference[], named };
return { positional: EMPTY_ARRAY as readonly Reactive[], named };
}

/*
Expand All @@ -247,7 +252,7 @@ export default class CurlyComponentManager
args: VMArguments,
{ isInteractive }: Environment,
dynamicScope: DynamicScope,
callerSelfRef: Reference,
callerSelfRef: Nullable<Reactive>,
hasBlock: boolean
): ComponentStateBucket {
// Get the nearest concrete component instance from the scope. "Virtual"
Expand Down Expand Up @@ -276,7 +281,8 @@ export default class CurlyComponentManager

// Save the current `this` context of the template as the component's
// `_target`, so bubbled actions are routed to the right place.
props._target = valueForRef(callerSelfRef);
assert('[BUG] caller unexpectedly null', callerSelfRef !== null);
props._target = unwrapReactive(callerSelfRef);

setOwner(props, owner);

Expand Down Expand Up @@ -358,7 +364,7 @@ export default class CurlyComponentManager
);
}

getSelf({ rootRef }: ComponentStateBucket): Reference {
getSelf({ rootRef }: ComponentStateBucket): Reactive {
return rootRef;
}

Expand All @@ -376,7 +382,7 @@ export default class CurlyComponentManager
applyAttributeBindings(attributeBindings, component, rootRef, operations);
} else {
let id = component.elementId ? component.elementId : guidFor(component);
operations.setAttribute('id', createPrimitiveRef(id), false, null);
operations.setAttribute('id', createPrimitiveCell(id), false, null);
}

if (classRef) {
Expand All @@ -386,7 +392,7 @@ export default class CurlyComponentManager

if (classNames && classNames.length) {
classNames.forEach((name: string) => {
operations.setAttribute('class', createPrimitiveRef(name), false, null);
operations.setAttribute('class', createPrimitiveCell(name), false, null);
});
}

Expand All @@ -398,7 +404,7 @@ export default class CurlyComponentManager
operations.setAttribute('class', EMBER_VIEW_REF, false, null);

if ('ariaRole' in component) {
operations.setAttribute('role', childRefFor(rootRef, 'ariaRole'), false, null);
operations.setAttribute('role', getReactiveProperty(rootRef, 'ariaRole'), false, null);
}

component._transitionTo('hasElement');
Expand Down
20 changes: 10 additions & 10 deletions packages/@ember/-internals/glimmer/lib/component-managers/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import type {
} from '@glimmer/interfaces';
import type { Nullable } from '@ember/-internals/utility-types';
import { capabilityFlagsFrom } from '@glimmer/manager';
import type { Reference } from '@glimmer/reference';
import { createConstRef, valueForRef } from '@glimmer/reference';
import type { Reactive } from '@glimmer/reference';

Check failure on line 22 in packages/@ember/-internals/glimmer/lib/component-managers/mount.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Module '"@glimmer/reference"' has no exported member 'Reactive'.

Check failure on line 22 in packages/@ember/-internals/glimmer/lib/component-managers/mount.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Module '"@glimmer/reference"' has no exported member 'Reactive'.
import { ReadonlyCell, unwrapReactive } from '@glimmer/reference';

Check failure on line 23 in packages/@ember/-internals/glimmer/lib/component-managers/mount.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Module '"@glimmer/reference"' has no exported member 'ReadonlyCell'.

Check failure on line 23 in packages/@ember/-internals/glimmer/lib/component-managers/mount.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Module '"@glimmer/reference"' has no exported member 'unwrapReactive'.

Check failure on line 23 in packages/@ember/-internals/glimmer/lib/component-managers/mount.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Module '"@glimmer/reference"' has no exported member 'ReadonlyCell'.

Check failure on line 23 in packages/@ember/-internals/glimmer/lib/component-managers/mount.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Module '"@glimmer/reference"' has no exported member 'unwrapReactive'.
import { unwrapTemplate } from '@glimmer/util';
import type RuntimeResolver from '../resolver';

interface EngineState {
engine: EngineInstance;
controller: any;
self: Reference;
modelRef?: Reference;
self: Reactive;
modelRef?: Reactive;
}

interface EngineDefinitionState {
Expand Down Expand Up @@ -90,7 +90,7 @@ class MountManager
let applicationFactory = engine.factoryFor(`controller:application`);
let controllerFactory = applicationFactory || generateControllerFactory(engine, 'application');
let controller: any;
let self: Reference;
let self: Reactive;
let bucket: EngineState;
let modelRef;

Expand All @@ -100,12 +100,12 @@ class MountManager

if (modelRef === undefined) {
controller = controllerFactory.create();
self = createConstRef(controller, 'this');
self = ReadonlyCell(controller, 'this');
bucket = { engine, controller, self, modelRef };
} else {
let model = valueForRef(modelRef);
let model = unwrapReactive(modelRef);
controller = controllerFactory.create({ model });
self = createConstRef(controller, 'this');
self = ReadonlyCell(controller, 'this');
bucket = { engine, controller, self, modelRef };
}

Expand Down Expand Up @@ -145,7 +145,7 @@ class MountManager
];
}

getSelf({ self }: EngineState): Reference {
getSelf({ self }: EngineState): Reactive {
return self;
}

Expand All @@ -163,7 +163,7 @@ class MountManager
let { controller, modelRef } = bucket;

if (modelRef !== undefined) {
controller.set('model', valueForRef(modelRef));
controller.set('model', unwrapReactive(modelRef));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import type {
} from '@glimmer/interfaces';
import type { Nullable } from '@ember/-internals/utility-types';
import { capabilityFlagsFrom } from '@glimmer/manager';
import type { Reference } from '@glimmer/reference';
import { createConstRef, valueForRef } from '@glimmer/reference';
import type { Reactive } from '@glimmer/reference';

Check failure on line 24 in packages/@ember/-internals/glimmer/lib/component-managers/outlet.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Module '"@glimmer/reference"' has no exported member 'Reactive'.

Check failure on line 24 in packages/@ember/-internals/glimmer/lib/component-managers/outlet.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Module '"@glimmer/reference"' has no exported member 'Reactive'.
import { ReadonlyCell, unwrapReactive } from '@glimmer/reference';

Check failure on line 25 in packages/@ember/-internals/glimmer/lib/component-managers/outlet.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Module '"@glimmer/reference"' has no exported member 'ReadonlyCell'.

Check failure on line 25 in packages/@ember/-internals/glimmer/lib/component-managers/outlet.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Module '"@glimmer/reference"' has no exported member 'ReadonlyCell'.
import { EMPTY_ARGS } from '@glimmer/runtime';
import { unwrapTemplate } from '@glimmer/util';

Expand All @@ -37,15 +37,15 @@ function instrumentationPayload(def: OutletDefinitionState) {
}

interface OutletInstanceState {
self: Reference;
self: Reactive;
outletBucket?: {};
engineBucket?: { mountPoint: string };
engine?: EngineInstance;
finalize: () => void;
}

export interface OutletDefinitionState {
ref: Reference<OutletState | undefined>;
ref: Reactive<OutletState | undefined>;
name: string;
template: Template;
controller: unknown;
Expand Down Expand Up @@ -86,16 +86,16 @@ class OutletComponentManager
dynamicScope.set('outletState', currentStateRef);

let state: OutletInstanceState = {
self: createConstRef(definition.controller, 'this'),
self: ReadonlyCell(definition.controller, 'this'),
finalize: _instrumentStart('render.outlet', instrumentationPayload, definition),
};

if (env.debugRenderTree !== undefined) {
state.outletBucket = {};

let parentState = valueForRef(parentStateRef);
let parentState = unwrapReactive(parentStateRef);
let parentOwner = parentState && parentState.render && parentState.render.owner;
let currentOwner = valueForRef(currentStateRef)!.render!.owner;
let currentOwner = unwrapReactive(currentStateRef)!.render!.owner;

if (parentOwner && parentOwner !== currentOwner) {
assert(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { tracked } from '@ember/-internals/metal';
import { assert } from '@ember/debug';
import { action } from '@ember/object';
import type { Reference } from '@glimmer/reference';
import { isConstRef, isUpdatableRef, updateRef, valueForRef } from '@glimmer/reference';
import type { Reactive } from '@glimmer/reference';
import { isConstant, isUpdatableRef, updateRef, unwrapReactive } from '@glimmer/reference';
import type { EventListener } from './internal';
import InternalComponent from './internal';

Expand All @@ -27,11 +27,11 @@ function devirtualize(callback: VirtualEventListener): EventListener {
return (event: Event) => callback(valueForEvent(event), event);
}

export function valueFrom(reference?: Reference<unknown>): Value {
export function valueFrom(reference?: Reactive<unknown>): Value {
if (reference === undefined) {
return new LocalValue(undefined);
} else if (isConstRef(reference)) {
return new LocalValue(valueForRef(reference));
} else if (isConstant(reference)) {
return new LocalValue(unwrapReactive(reference));
} else if (isUpdatableRef(reference)) {
return new UpstreamValue(reference);
} else {
Expand Down Expand Up @@ -61,10 +61,10 @@ class LocalValue implements Value {
}

class UpstreamValue implements Value {
constructor(private reference: Reference<unknown>) {}
constructor(private reference: Reactive<unknown>) {}

get(): unknown {
return valueForRef(this.reference);
return unwrapReactive(this.reference);
}

set(value: unknown): void {
Expand All @@ -78,7 +78,7 @@ class ForkedValue implements Value {

private lastUpstreamValue = UNINITIALIZED;

constructor(reference: Reference<unknown>) {
constructor(reference: Reactive<unknown>) {
this.upstream = new UpstreamValue(reference);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/@ember/-internals/glimmer/lib/components/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { hasDOM } from '@ember/-internals/browser-environment';
import { type Opaque } from '@ember/-internals/utility-types';
import { assert, warn } from '@ember/debug';
import { action } from '@ember/object';
import { valueForRef } from '@glimmer/reference';
import { unwrapReactive } from '@glimmer/reference';
import { untrack } from '@glimmer/validator';
import InputTemplate from '../templates/input';
import AbstractInput, { valueFrom } from './abstract-input';
Expand Down Expand Up @@ -209,7 +209,7 @@ class _Input extends AbstractInput {
() =>
this.args.named['checked'] !== undefined ||
this.args.named['value'] === undefined ||
typeof valueForRef(this.args.named['value']) === 'string'
typeof unwrapReactive(this.args.named['value']) === 'string'
),
{ id: 'ember.built-in-components.input-checkbox-value' }
);
Expand All @@ -229,7 +229,7 @@ class _Input extends AbstractInput {
() =>
this.args.named['checked'] !== undefined ||
this.args.named['value'] === undefined ||
typeof valueForRef(this.args.named['value']) === 'string'
typeof unwrapReactive(this.args.named['value']) === 'string'
),
{ id: 'ember.built-in-components.input-checkbox-value' }
);
Expand Down
18 changes: 9 additions & 9 deletions packages/@ember/-internals/glimmer/lib/components/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import type {
WithCreateInstance,
} from '@glimmer/interfaces';
import { setComponentTemplate, setInternalComponentManager } from '@glimmer/manager';
import type { Reference } from '@glimmer/reference';
import { createConstRef, isConstRef, valueForRef } from '@glimmer/reference';
import type { Reactive } from '@glimmer/reference';
import { ReadonlyCell, isConstant, unwrapReactive } from '@glimmer/reference';
import { untrack } from '@glimmer/validator';

function NOOP(): void {}
Expand Down Expand Up @@ -68,12 +68,12 @@ export default class InternalComponent {

protected named(name: string): unknown {
let ref = this.args.named[name];
return ref ? valueForRef(ref) : undefined;
return ref ? unwrapReactive(ref) : undefined;
}

protected positional(index: number): unknown {
let ref = this.args.positional[index];
return ref ? valueForRef(ref) : undefined;
return ref ? unwrapReactive(ref) : undefined;
}

protected listenerFor(name: string): EventListener {
Expand Down Expand Up @@ -188,13 +188,13 @@ class InternalManager
args: VMArguments,
_env: Environment,
_dynamicScope: DynamicScope,
caller: Reference
caller: Reactive
): InternalComponent {
assert('caller must be const', isConstRef(caller));
assert('caller must be const', isConstant(caller));

let ComponentClass = deopaquify(definition);

let instance = new ComponentClass(owner, args.capture(), valueForRef(caller));
let instance = new ComponentClass(owner, args.capture(), unwrapReactive(caller));

untrack(instance['validateArguments'].bind(instance));

Expand All @@ -211,8 +211,8 @@ class InternalManager
return definition.toString();
}

getSelf(instance: InternalComponent): Reference {
return createConstRef(instance, 'this');
getSelf(instance: InternalComponent): Reactive {
return ReadonlyCell(instance, 'this');
}

getDestroyable(instance: InternalComponent): Destroyable {
Expand Down
Loading

0 comments on commit 2d8a515

Please sign in to comment.