diff --git a/packages/@ember/-internals/glimmer/lib/component-managers/mount.ts b/packages/@ember/-internals/glimmer/lib/component-managers/mount.ts index cf0bd78b57f..c1911994289 100644 --- a/packages/@ember/-internals/glimmer/lib/component-managers/mount.ts +++ b/packages/@ember/-internals/glimmer/lib/component-managers/mount.ts @@ -1,5 +1,6 @@ import { Owner } from '@ember/-internals/owner'; import { generateControllerFactory } from '@ember/-internals/routing'; +import { assert } from '@ember/debug'; import EngineInstance from '@ember/engine/instance'; import { associateDestroyableChild } from '@glimmer/destroyable'; import { @@ -74,6 +75,7 @@ class MountManager // we should resolve the engine app template in the helper // it also should use the owner that looked up the mount helper. + assert('Expected owner to be an EngineInstance', owner instanceof EngineInstance); let engine = owner.buildChildEngineInstance(name); engine.boot(); diff --git a/packages/@ember/-internals/glimmer/lib/component-managers/outlet.ts b/packages/@ember/-internals/glimmer/lib/component-managers/outlet.ts index a2f904ea418..0ad930765ba 100644 --- a/packages/@ember/-internals/glimmer/lib/component-managers/outlet.ts +++ b/packages/@ember/-internals/glimmer/lib/component-managers/outlet.ts @@ -95,14 +95,14 @@ class OutletComponentManager let currentOwner = valueForRef(currentStateRef)!.render!.owner; if (parentOwner && parentOwner !== currentOwner) { - let engine = currentOwner as EngineInstance; + assert( + 'Expected currentOwner to be an EngineInstance', + currentOwner instanceof EngineInstance + ); - assert('invalid engine: missing mountPoint', typeof currentOwner.mountPoint === 'string'); - assert('invalid engine: missing routable', currentOwner.routable === true); + let mountPoint = currentOwner.mountPoint; - let mountPoint = engine.mountPoint!; - - state.engine = engine; + state.engine = currentOwner; state.engineBucket = { mountPoint }; } } diff --git a/packages/@ember/-internals/glimmer/lib/components/link-to.ts b/packages/@ember/-internals/glimmer/lib/components/link-to.ts index 0320e62a57c..5025ff4ef57 100644 --- a/packages/@ember/-internals/glimmer/lib/components/link-to.ts +++ b/packages/@ember/-internals/glimmer/lib/components/link-to.ts @@ -1,4 +1,3 @@ -import { Owner } from '@ember/-internals/owner'; import { Route, RouterState, RoutingService } from '@ember/-internals/routing'; import { isSimpleClick } from '@ember/-internals/views'; import { assert, debugFreeze, inspect, warn } from '@ember/debug'; @@ -490,11 +489,13 @@ class LinkTo extends InternalComponent { } private get isEngine(): boolean { - return getEngineParent(this.owner as EngineInstance) !== undefined; + let owner = this.owner; + return owner instanceof EngineInstance && getEngineParent(owner) !== undefined; } private get engineMountPoint(): string | undefined { - return (this.owner as Owner | EngineInstance).mountPoint; + let owner = this.owner; + return owner instanceof EngineInstance ? owner.mountPoint : undefined; } private classFor(state: 'active' | 'loading' | 'disabled'): string { diff --git a/packages/@ember/-internals/glimmer/tests/integration/application/debug-render-tree-test.ts b/packages/@ember/-internals/glimmer/tests/integration/application/debug-render-tree-test.ts index 05cde32219d..8ec31d978e2 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/application/debug-render-tree-test.ts +++ b/packages/@ember/-internals/glimmer/tests/integration/application/debug-render-tree-test.ts @@ -7,12 +7,12 @@ import { import { ENV } from '@ember/-internals/environment'; import { Component, setComponentManager } from '@ember/-internals/glimmer'; -import { EngineInstanceOptions, Owner } from '@ember/-internals/owner'; +import { Owner } from '@ember/-internals/owner'; import { Route } from '@ember/-internals/routing'; import Controller from '@ember/controller'; import { assert, captureRenderTree } from '@ember/debug'; import Engine from '@ember/engine'; -import EngineInstance from '@ember/engine/instance'; +import EngineInstance, { EngineInstanceOptions } from '@ember/engine/instance'; import { CapturedRenderNode } from '@glimmer/interfaces'; import { componentCapabilities, setComponentTemplate } from '@glimmer/manager'; import { templateOnlyComponent } from '@glimmer/runtime'; diff --git a/packages/@ember/-internals/owner/index.ts b/packages/@ember/-internals/owner/index.ts index b355f45ea5d..4448d616c1e 100644 --- a/packages/@ember/-internals/owner/index.ts +++ b/packages/@ember/-internals/owner/index.ts @@ -1,9 +1,12 @@ import { getOwner as glimmerGetOwner, setOwner as glimmerSetOwner } from '@glimmer/owner'; +import { TypeOptions } from '../container/lib/registry'; /** @module @ember/application */ +export { TypeOptions }; + export interface FactoryClass { positionalParams?: string | string[] | undefined | null; } @@ -16,25 +19,26 @@ export interface Factory { create(props?: { [prop: string]: any }): T; } -export interface EngineInstanceOptions { - mountPoint: string; - routable: boolean; -} - -import EngineInstance from '@ember/engine/instance'; -import { TypeOptions } from '../container/lib/registry'; +// A combination of the public methods on ContainerProxyMixin and RegistryProxyMixin export interface Owner { + // From ContainerProxy + ownerInjection(): void; lookup(fullName: string, options?: TypeOptions): unknown; factoryFor(fullName: string): Factory | undefined; - register(fullName: string, factory: Factory, options?: TypeOptions): void; - hasRegistration(name: string): boolean; - /** @internal */ - mountPoint?: string; - /** @internal */ - routable?: boolean; - /** @internal */ - buildChildEngineInstance(name: string, options?: EngineInstanceOptions): EngineInstance; + // From RegistryProxy + resolveRegistration(fullName: string): Factory | undefined; + register(fullName: string, factory: Factory, options?: TypeOptions): void; + unregister(fullName: string): void; + hasRegistration(fullName: string): boolean; + registeredOption( + fullName: string, + optionName: K + ): TypeOptions[K] | undefined; + registerOptions(fullName: string, options: TypeOptions): void; + registeredOptions(fullName: string): TypeOptions | undefined; + registerOptionsForType(type: string, options: TypeOptions): void; + registeredOptionsForType(type: string): TypeOptions | undefined; } /** diff --git a/packages/@ember/-internals/routing/lib/system/route.ts b/packages/@ember/-internals/routing/lib/system/route.ts index 6cc78f42568..ccee0955350 100644 --- a/packages/@ember/-internals/routing/lib/system/route.ts +++ b/packages/@ember/-internals/routing/lib/system/route.ts @@ -23,6 +23,7 @@ import { import { isProxy, lookupDescriptor, symbol } from '@ember/-internals/utils'; import Controller from '@ember/controller'; import { assert, info, isTesting } from '@ember/debug'; +import EngineInstance from '@ember/engine/instance'; import { dependentKeyCompat } from '@ember/object/compat'; import { once } from '@ember/runloop'; import { DEBUG } from '@glimmer/env'; @@ -548,7 +549,7 @@ class Route _setRouteName(name: string) { this.routeName = name; let owner = getOwner(this); - assert('Route is unexpectedly missing an owner', owner); + assert('Expected route to have EngineInstance as owner', owner instanceof EngineInstance); this.fullRouteName = getEngineRouteName(owner, name)!; } @@ -1679,7 +1680,7 @@ class Route modelFor(_name: string): unknown | undefined { let name; let owner = getOwner(this); - assert('Route is unexpectedly missing an owner', owner); + assert('Expected router owner to be an EngineInstance', owner instanceof EngineInstance); let transition = this._router && this._router._routerMicrolib ? this._router._routerMicrolib.activeTransition @@ -2332,7 +2333,7 @@ function addQueryParamsObservers(controller: any, propNames: string[]) { }); } -function getEngineRouteName(engine: Owner, routeName: string) { +function getEngineRouteName(engine: EngineInstance, routeName: string) { if (engine.routable) { let prefix = engine.mountPoint; diff --git a/packages/@ember/-internals/routing/lib/system/router.ts b/packages/@ember/-internals/routing/lib/system/router.ts index bf2907212d7..22a815443b4 100644 --- a/packages/@ember/-internals/routing/lib/system/router.ts +++ b/packages/@ember/-internals/routing/lib/system/router.ts @@ -46,6 +46,7 @@ import Router, { TransitionState, } from 'router_js'; import { EngineRouteInfo } from './engines'; +import EngineInstance from '@ember/engine/instance'; function defaultDidTransition( this: EmberRouter, @@ -113,11 +114,6 @@ interface OutletState { wasUsed?: boolean; } -interface EngineInstance extends Owner { - boot(): void; - destroy(): void; -} - export interface QueryParam { prop: string; urlKey: string; @@ -1409,7 +1405,7 @@ class EmberRouter extends EmberObject.extend(Evented) i if (!engineInstance) { let owner = getOwner(this); - assert('Router is unexpectedly missing an owner', owner); + assert('Expected router to have EngineInstance as owner', owner instanceof EngineInstance); assert( `You attempted to mount the engine '${name}' in your router map, but the engine can not be found.`, diff --git a/packages/@ember/-internals/routing/lib/utils.ts b/packages/@ember/-internals/routing/lib/utils.ts index 6589ccff7d1..cb97efa92fb 100644 --- a/packages/@ember/-internals/routing/lib/utils.ts +++ b/packages/@ember/-internals/routing/lib/utils.ts @@ -1,6 +1,7 @@ import { get } from '@ember/-internals/metal'; import { getOwner } from '@ember/-internals/owner'; import { assert, deprecate } from '@ember/debug'; +import EngineInstance from '@ember/engine/instance'; import EmberError from '@ember/error'; import Router, { STATE_SYMBOL, InternalRouteInfo, ModelFor } from 'router_js'; import Route from './system/route'; @@ -247,7 +248,7 @@ export function prefixRouteNameArg | UnnamedRout ): T { let routeName: string; let owner = getOwner(route); - assert('Route is unexpectedly missing an owner', owner); + assert('Expected route to have EngineInstance as owner', owner instanceof EngineInstance); let prefix = owner.mountPoint; diff --git a/packages/@ember/-internals/runtime/lib/mixins/container_proxy.d.ts b/packages/@ember/-internals/runtime/lib/mixins/container_proxy.d.ts index 31d9dbee6b1..2f9cbf8e112 100644 --- a/packages/@ember/-internals/runtime/lib/mixins/container_proxy.d.ts +++ b/packages/@ember/-internals/runtime/lib/mixins/container_proxy.d.ts @@ -1,10 +1,15 @@ import { Container } from '@ember/-internals/container'; +import { TypeOptions } from '@ember/-internals/container/lib/registry'; +import { Factory } from '@ember/-internals/owner'; import Mixin from '../../types/mixin'; interface ContainerProxy { - ownerInjection: Container['ownerInjection']; - lookup: Container['lookup']; - factoryFor: Container['factoryFor']; + /** @internal */ + __container__: Container; + + ownerInjection(): void; + lookup(fullName: string, options?: TypeOptions): unknown; + factoryFor(fullName: string): Factory | undefined; } declare const ContainerProxy: Mixin; diff --git a/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.d.ts b/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.d.ts index b18c207573b..08b5901250a 100644 --- a/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.d.ts +++ b/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.d.ts @@ -1,16 +1,23 @@ import { Registry } from '@ember/-internals/container'; +import { TypeOptions } from '@ember/-internals/container/lib/registry'; +import { Factory } from '@ember/-internals/owner'; import Mixin from '../../types/mixin'; interface RegistryProxyMixin { - resolveRegistration: Registry['resolve']; - register: Registry['register']; - unregister: Registry['unregister']; - hasRegistration: Registry['has']; - registeredOption: Registry['getOption']; - registerOptions: Registry['options']; - registeredOptions: Registry['getOptions']; - registerOptionsForType: Registry['optionsForType']; - registeredOptionsForType: Registry['getOptionsForType']; + /** @internal */ + __registry__: Registry; + resolveRegistration(fullName: string): Factory | undefined; + register(fullName: string, factory: Factory, options?: TypeOptions): void; + unregister(fullName: string): void; + hasRegistration(fullName: string): boolean; + registeredOption( + fullName: string, + optionName: K + ): TypeOptions[K] | undefined; + registerOptions(fullName: string, options: TypeOptions): void; + registeredOptions(fullName: string): TypeOptions | undefined; + registerOptionsForType(type: string, options: TypeOptions): void; + registeredOptionsForType(type: string): TypeOptions | undefined; } declare const RegistryProxyMixin: Mixin; diff --git a/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js b/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js index 5f7a011dca9..59d1c4f70e1 100644 --- a/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js +++ b/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js @@ -254,6 +254,7 @@ export default Mixin.create({ @param factoryNameOrType {String} @param property {String} @param injectionName {String} + @deprecated **/ inject: registryAlias('injection'), }); diff --git a/packages/@ember/application/lib/application.d.ts b/packages/@ember/application/lib/application.d.ts index bb3f709db98..96c93190ac6 100644 --- a/packages/@ember/application/lib/application.d.ts +++ b/packages/@ember/application/lib/application.d.ts @@ -1,6 +1,6 @@ -import { EngineInstanceOptions } from '@ember/-internals/owner'; import { EventDispatcher } from '@ember/-internals/views'; import Engine from '@ember/engine'; +import { EngineInstanceOptions } from '@ember/engine/instance'; import ApplicationInstance, { BootOptions } from '../instance'; export default class Application extends Engine { diff --git a/packages/@ember/engine/index.d.ts b/packages/@ember/engine/index.d.ts index 36a691b14a1..a867217311b 100644 --- a/packages/@ember/engine/index.d.ts +++ b/packages/@ember/engine/index.d.ts @@ -1,5 +1,4 @@ -import EngineInstance from './instance'; -import { EngineInstanceOptions } from '@ember/-internals/owner'; +import EngineInstance, { EngineInstanceOptions } from './instance'; import { Namespace, RegistryProxyMixin } from '@ember/-internals/runtime'; export { getEngineParent } from '@ember/engine/lib/engine-parent'; diff --git a/packages/@ember/engine/instance.d.ts b/packages/@ember/engine/instance.d.ts index 76516f6f970..7dd7f96164f 100644 --- a/packages/@ember/engine/instance.d.ts +++ b/packages/@ember/engine/instance.d.ts @@ -3,12 +3,18 @@ import { Owner } from '@ember/-internals/owner'; import { BootOptions } from '@ember/application/instance'; import EmberObject from '@ember/object'; +export interface EngineInstanceOptions { + mountPoint: string; + routable: boolean; +} + interface EngineInstance extends RegistryProxyMixin, ContainerProxyMixin, Owner {} declare class EngineInstance extends EmberObject { - init(...args: unknown[]): void; boot(options?: BootOptions): void; - unregister(fullName: string): void; + mountPoint: string; + routable: boolean; + buildChildEngineInstance(name: string, options?: EngineInstanceOptions): EngineInstance; } export default EngineInstance;