Skip to content

Commit d68bf5e

Browse files
authored
Merge pull request #20734 from emberjs/circularity
working to remove circular dependencies
2 parents 85a4f29 + 0945aac commit d68bf5e

File tree

35 files changed

+174
-128
lines changed

35 files changed

+174
-128
lines changed

packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ export default class CurlyComponentManager
260260

261261
beginTrackFrame();
262262
let props = processComponentArgs(capturedArgs);
263+
props[ARGS] = capturedArgs;
263264
let argsTag = endTrackFrame();
264265

265266
// Alias `id` argument to `elementId` property on the component instance.

packages/@ember/-internals/glimmer/lib/components/link-to.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type Route from '@ember/routing/route';
22
import type { RouterState, RoutingService } from '@ember/routing/-internals';
33
import { isSimpleClick } from '@ember/-internals/views';
44
import { assert, debugFreeze, inspect, warn } from '@ember/debug';
5-
import { getEngineParent } from '@ember/engine';
6-
import EngineInstance from '@ember/engine/instance';
5+
import { getEngineParent } from '@ember/engine/parent';
6+
import type EngineInstance from '@ember/engine/instance';
77
import { flaggedInstrument } from '@ember/instrumentation';
88
import { action } from '@ember/object';
99
import { service } from '@ember/service';
@@ -494,13 +494,13 @@ class _LinkTo extends InternalComponent {
494494
}
495495

496496
private get isEngine(): boolean {
497-
let owner = this.owner;
498-
return owner instanceof EngineInstance && getEngineParent(owner) !== undefined;
497+
let owner = this.owner as EngineInstance;
498+
return getEngineParent(owner) !== undefined;
499499
}
500500

501501
private get engineMountPoint(): string | undefined {
502-
let owner = this.owner;
503-
return owner instanceof EngineInstance ? owner.mountPoint : undefined;
502+
let owner = this.owner as EngineInstance;
503+
return owner.mountPoint;
504504
}
505505

506506
private classFor(state: 'active' | 'loading' | 'disabled'): string {

packages/@ember/-internals/glimmer/lib/templates/input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { precompileTemplate } from '@ember/template-compilation';
2-
import { on } from '@ember/modifier';
2+
import { on } from '@ember/modifier/on';
33
export default precompileTemplate(
44
`<input
55
{{!-- for compatibility --}}

packages/@ember/-internals/glimmer/lib/templates/link-to.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { precompileTemplate } from '@ember/template-compilation';
2-
import { on } from '@ember/modifier';
2+
import { on } from '@ember/modifier/on';
33

44
export default precompileTemplate(
55
`<a

packages/@ember/-internals/glimmer/lib/templates/textarea.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { precompileTemplate } from '@ember/template-compilation';
2-
import { on } from '@ember/modifier';
2+
import { on } from '@ember/modifier/on';
33

44
export default precompileTemplate(
55
`<textarea

packages/@ember/-internals/glimmer/lib/utils/process-args.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { CapturedNamedArguments } from '@glimmer/interfaces';
33
import type { Reference } from '@glimmer/reference';
44
import { isUpdatableRef, updateRef, valueForRef } from '@glimmer/reference';
55
import { assert } from '@ember/debug';
6-
import { ARGS } from '../component-managers/curly';
76
import { ACTIONS } from '../helpers/action';
87

98
// ComponentArgs takes EvaluatedNamedArgs and converts them into the
@@ -13,8 +12,6 @@ export function processComponentArgs(namedArgs: CapturedNamedArguments) {
1312
let attrs = Object.create(null);
1413
let props = Object.create(null);
1514

16-
props[ARGS] = namedArgs;
17-
1815
for (let name in namedArgs) {
1916
let ref = namedArgs[name];
2017
assert('expected ref', ref);

packages/@ember/-internals/glimmer/lib/utils/to-bool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isHTMLSafe } from '@ember/-internals/glimmer';
1+
import { isHTMLSafe } from './string';
22
import { get, tagForProperty } from '@ember/-internals/metal';
33
import { isArray } from '@ember/array';
44
import { isProxy } from '@ember/-internals/utils';

packages/@ember/-internals/metal/lib/array.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ interface ObservedObject {
1212
_revalidate?: () => void;
1313
}
1414

15-
export function objectAt<T>(array: T[] | EmberArray<T>, index: number): T | undefined {
16-
if (Array.isArray(array)) {
17-
return array[index];
18-
} else {
19-
return array.objectAt(index);
20-
}
21-
}
15+
export { objectAt } from './object-at';
2216

2317
// Ideally, we'd use MutableArray.detect but for unknown reasons this causes
2418
// the node tests to fail strangely.

packages/@ember/-internals/metal/lib/chain-tags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
updateTag,
1111
validateTag,
1212
} from '@glimmer/validator';
13-
import { objectAt } from './array';
13+
import { objectAt } from './object-at';
1414
import { tagForProperty } from './tags';
1515

1616
export const CHAIN_PASS_THROUGH = new WeakSet();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type EmberArray from '@ember/array';
2+
3+
export function objectAt<T>(array: T[] | EmberArray<T>, index: number): T | undefined {
4+
if (Array.isArray(array)) {
5+
return array[index];
6+
} else {
7+
return array.objectAt(index);
8+
}
9+
}

packages/@ember/-internals/metal/lib/observer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ENV } from '@ember/-internals/environment';
22
import { peekMeta } from '@ember/-internals/meta';
3-
import { schedule } from '@ember/runloop';
3+
import type { schedule } from '@ember/runloop';
44
import { registerDestructor } from '@glimmer/destroyable';
55
import type { Tag } from '@glimmer/validator';
66
import { CURRENT_TAG, tagMetaFor, validateTag, valueForTag } from '@glimmer/validator';
@@ -187,7 +187,7 @@ export function revalidateObservers(target: object) {
187187

188188
let lastKnownRevision = 0;
189189

190-
export function flushAsyncObservers(shouldSchedule = true) {
190+
export function flushAsyncObservers(_schedule: typeof schedule | false) {
191191
let currentRevision = valueForTag(CURRENT_TAG);
192192
if (lastKnownRevision === currentRevision) {
193193
return;
@@ -213,8 +213,8 @@ export function flushAsyncObservers(shouldSchedule = true) {
213213
}
214214
};
215215

216-
if (shouldSchedule) {
217-
schedule('actions', sendObserver);
216+
if (_schedule) {
217+
_schedule('actions', sendObserver);
218218
} else {
219219
sendObserver();
220220
}

packages/@ember/-internals/views/lib/system/event_dispatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getOwner } from '@ember/-internals/owner';
22
import { assert } from '@ember/debug';
33
import { get, set } from '@ember/-internals/metal';
44
import EmberObject from '@ember/object';
5-
import { getElementView } from '@ember/-internals/views';
5+
import { getElementView } from './utils';
66
import ActionManager from './action_manager';
77
import type { BootEnvironment } from '@ember/-internals/glimmer/lib/views/outlet';
88
import type Component from '@ember/component';

packages/@ember/array/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type { MethodNamesOf, MethodParams, MethodReturns } from '@ember/-interna
2222
import type { ComputedPropertyCallback } from '@ember/-internals/metal';
2323
import { isEmberArray, setEmberArray } from '@ember/array/-internals';
2424

25-
export { default as makeArray } from './lib/make-array';
25+
export { default as makeArray } from './make';
2626

2727
export type EmberArrayLike<T> = EmberArray<T> | NativeArray<T>;
2828

packages/@ember/array/make.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './lib/make-array';

packages/@ember/array/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
".": "./index.ts",
77
"./-internals": "./-internals.ts",
88
"./proxy": "./proxy.ts",
9+
"./make": "./make.ts",
910
"./mutable": "./mutable.ts"
1011
},
1112
"dependencies": {

packages/@ember/debug/index.ts

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import defaultDeprecate from './lib/deprecate';
66
import { isTesting } from './lib/testing';
77
import type { WarnFunc } from './lib/warn';
88
import _warn from './lib/warn';
9+
import { assert, setAssert } from './lib/assert';
910

1011
export { registerHandler as registerWarnHandler } from './lib/warn';
1112
export {
@@ -27,10 +28,6 @@ export type DebugFunctionType =
2728
| 'runInDebug'
2829
| 'deprecateFunc';
2930

30-
export interface AssertFunc {
31-
(desc: string, condition: unknown): asserts condition;
32-
(desc: string): never;
33-
}
3431
export type DebugFunc = (message: string) => void;
3532
export type DebugSealFunc = (obj: object) => void;
3633
export type DebugFreezeFunc = (obj: object) => void;
@@ -43,7 +40,7 @@ export type DeprecateFuncFunc = (
4340
) => Function;
4441

4542
export type GetDebugFunction = {
46-
(type: 'assert'): AssertFunc;
43+
(type: 'assert'): typeof assert;
4744
(type: 'info'): InfoFunc;
4845
(type: 'warn'): WarnFunc;
4946
(type: 'debug'): DebugFunc;
@@ -55,7 +52,7 @@ export type GetDebugFunction = {
5552
};
5653

5754
export type SetDebugFunction = {
58-
(type: 'assert', func: AssertFunc): AssertFunc;
55+
(type: 'assert', func: typeof assert): typeof assert;
5956
(type: 'info', func: InfoFunc): InfoFunc;
6057
(type: 'warn', func: WarnFunc): WarnFunc;
6158
(type: 'debug', func: DebugFunc): DebugFunc;
@@ -71,7 +68,6 @@ const noop = () => {};
7168

7269
// SAFETY: these casts are just straight-up lies, but the point is that they do
7370
// not do anything in production builds.
74-
let assert: AssertFunc = noop as unknown as AssertFunc;
7571
let info: InfoFunc = noop;
7672
let warn: WarnFunc = noop;
7773
let debug: DebugFunc = noop;
@@ -94,7 +90,7 @@ if (DEBUG) {
9490
setDebugFunction = function (type: DebugFunctionType, callback: Function) {
9591
switch (type) {
9692
case 'assert':
97-
return (assert = callback as AssertFunc);
93+
return setAssert(callback as typeof assert);
9894
case 'info':
9995
return (info = callback as InfoFunc);
10096
case 'warn':
@@ -143,51 +139,6 @@ if (DEBUG) {
143139
*/
144140

145141
if (DEBUG) {
146-
/**
147-
Verify that a certain expectation is met, or throw a exception otherwise.
148-
149-
This is useful for communicating assumptions in the code to other human
150-
readers as well as catching bugs that accidentally violates these
151-
expectations.
152-
153-
Assertions are removed from production builds, so they can be freely added
154-
for documentation and debugging purposes without worries of incuring any
155-
performance penalty. However, because of that, they should not be used for
156-
checks that could reasonably fail during normal usage. Furthermore, care
157-
should be taken to avoid accidentally relying on side-effects produced from
158-
evaluating the condition itself, since the code will not run in production.
159-
160-
```javascript
161-
import { assert } from '@ember/debug';
162-
163-
// Test for truthiness
164-
assert('Must pass a string', typeof str === 'string');
165-
166-
// Fail unconditionally
167-
assert('This code path should never be run');
168-
```
169-
170-
@method assert
171-
@static
172-
@for @ember/debug
173-
@param {String} description Describes the expectation. This will become the
174-
text of the Error thrown if the assertion fails.
175-
@param {any} condition Must be truthy for the assertion to pass. If
176-
falsy, an exception will be thrown.
177-
@public
178-
@since 1.0.0
179-
*/
180-
function assert(desc: string): never;
181-
function assert(desc: string, test: unknown): asserts test;
182-
// eslint-disable-next-line no-inner-declarations
183-
function assert(desc: string, test?: unknown): asserts test {
184-
if (!test) {
185-
throw new Error(`Assertion Failed: ${desc}`);
186-
}
187-
}
188-
189-
setDebugFunction('assert', assert);
190-
191142
/**
192143
Display a debug notice.
193144

packages/@ember/debug/lib/assert.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { DEBUG } from '@glimmer/env';
2+
3+
export interface AssertFunc {
4+
(desc: string, condition: unknown): asserts condition;
5+
(desc: string): never;
6+
}
7+
8+
export let assert: AssertFunc = (() => {}) as unknown as AssertFunc;
9+
10+
export function setAssert(implementation: typeof assert): typeof assert {
11+
assert = implementation;
12+
return implementation;
13+
}
14+
15+
if (DEBUG) {
16+
/**
17+
Verify that a certain expectation is met, or throw a exception otherwise.
18+
19+
This is useful for communicating assumptions in the code to other human
20+
readers as well as catching bugs that accidentally violates these
21+
expectations.
22+
23+
Assertions are removed from production builds, so they can be freely added
24+
for documentation and debugging purposes without worries of incuring any
25+
performance penalty. However, because of that, they should not be used for
26+
checks that could reasonably fail during normal usage. Furthermore, care
27+
should be taken to avoid accidentally relying on side-effects produced from
28+
evaluating the condition itself, since the code will not run in production.
29+
30+
```javascript
31+
import { assert } from '@ember/debug';
32+
33+
// Test for truthiness
34+
assert('Must pass a string', typeof str === 'string');
35+
36+
// Fail unconditionally
37+
assert('This code path should never be run');
38+
```
39+
40+
@method assert
41+
@static
42+
@for @ember/debug
43+
@param {String} description Describes the expectation. This will become the
44+
text of the Error thrown if the assertion fails.
45+
@param {any} condition Must be truthy for the assertion to pass. If
46+
falsy, an exception will be thrown.
47+
@public
48+
@since 1.0.0
49+
*/
50+
function assert(desc: string): never;
51+
function assert(desc: string, test: unknown): asserts test;
52+
// eslint-disable-next-line no-inner-declarations
53+
function assert(desc: string, test?: unknown): asserts test {
54+
if (!test) {
55+
throw new Error(`Assertion Failed: ${desc}`);
56+
}
57+
}
58+
setAssert(assert);
59+
}

packages/@ember/debug/lib/deprecate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ENV } from '@ember/-internals/environment';
22
import { DEBUG } from '@glimmer/env';
33

4-
import { assert } from '../index';
4+
import { assert } from './assert';
55
import type { HandlerCallback } from './handlers';
66
import { invoke, registerHandler as genericRegisterHandler } from './handlers';
77

packages/@ember/debug/lib/inspect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert } from '@ember/debug';
1+
import { assert } from './assert';
22
const { toString: objectToString } = Object.prototype;
33
const { toString: functionToString } = Function.prototype;
44
const { isArray } = Array;

packages/@ember/debug/lib/warn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DEBUG } from '@glimmer/env';
22

3-
import { assert } from '../index';
3+
import { assert } from './assert';
44
import type { HandlerCallback } from './handlers';
55
import { invoke, registerHandler as genericRegisterHandler } from './handlers';
66

packages/@ember/engine/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { getEngineParent, setEngineParent } from './lib/engine-parent';
1+
export { getEngineParent, setEngineParent } from './parent';
22

33
import { canInvoke } from '@ember/-internals/utils';
44
import Controller from '@ember/controller';

packages/@ember/engine/instance.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { RSVP } from '@ember/-internals/runtime';
77
import { assert } from '@ember/debug';
88
import { Registry, privatize as P } from '@ember/-internals/container';
99
import { guidFor } from '@ember/-internals/utils';
10-
import { ENGINE_PARENT, getEngineParent, setEngineParent } from './lib/engine-parent';
10+
import { ENGINE_PARENT, getEngineParent, setEngineParent } from './parent';
1111
import { ContainerProxyMixin, RegistryProxyMixin } from '@ember/-internals/runtime';
1212
import type { InternalOwner } from '@ember/-internals/owner';
1313
import type Owner from '@ember/-internals/owner';
1414
import { type FullName, isFactory } from '@ember/-internals/owner';
15-
import Engine from '@ember/engine';
15+
import type Engine from '@ember/engine';
1616
import type Application from '@ember/application';
1717
import type { BootEnvironment } from '@ember/-internals/glimmer';
1818
import type { SimpleElement } from '@simple-dom/interface';
@@ -199,16 +199,14 @@ class EngineInstance extends EmberObject.extend(RegistryProxyMixin, ContainerPro
199199
@return {EngineInstance,Error}
200200
*/
201201
buildChildEngineInstance(name: string, options: EngineInstanceOptions = {}): EngineInstance {
202-
let ChildEngine = this.lookup(`engine:${name}`);
202+
let ChildEngine = this.lookup(`engine:${name}`) as Engine;
203203

204204
if (!ChildEngine) {
205205
throw new Error(
206206
`You attempted to mount the engine '${name}', but it is not registered with its parent.`
207207
);
208208
}
209209

210-
assert('expected an Engine', ChildEngine instanceof Engine);
211-
212210
let engineInstance = ChildEngine.buildInstance(options);
213211

214212
setEngineParent(engineInstance, this);

0 commit comments

Comments
 (0)