@@ -10,8 +10,13 @@ import type { Container } from '@ember/-internals/container';
1010import { Registry , privatize as P } from '@ember/-internals/container' ;
1111import { guidFor } from '@ember/-internals/utils' ;
1212import { ENGINE_PARENT , getEngineParent , setEngineParent } from './parent' ;
13- import { RegistryProxyMixin } from '@ember/-internals/runtime' ;
14- import type { ContainerProxy , InternalOwner , RegisterOptions } from '@ember/-internals/owner' ;
13+ import type {
14+ ContainerProxy ,
15+ FactoryClass ,
16+ InternalFactory ,
17+ InternalOwner ,
18+ RegisterOptions ,
19+ } from '@ember/-internals/owner' ;
1520import type Owner from '@ember/-internals/owner' ;
1621import { type FullName , isFactory } from '@ember/-internals/owner' ;
1722import type Engine from '@ember/engine' ;
@@ -42,7 +47,6 @@ export interface EngineInstanceOptions {
4247 @public
4348 @class EngineInstance
4449 @extends EmberObject
45- @uses RegistryProxyMixin
4650*/
4751
4852// TODO: Update this comment
@@ -53,11 +57,9 @@ export interface EngineInstanceOptions {
5357// clauses for `InternalOwner` and `Owner` is to keep us honest: if this stops
5458// type checking, we have broken part of our public API contract. Medium-term,
5559// the goal here is to `EngineInstance` simple be `Owner`.
56- interface EngineInstance extends RegistryProxyMixin , InternalOwner , Owner { }
57- class EngineInstance
58- extends EmberObject . extend ( RegistryProxyMixin )
59- implements ContainerProxy , InternalOwner , Owner
60- {
60+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
61+ interface EngineInstance extends Owner { }
62+ class EngineInstance extends EmberObject implements ContainerProxy , InternalOwner , Owner {
6163 /**
6264 @private
6365 @method setupRegistry
@@ -174,23 +176,6 @@ class EngineInstance
174176 ( this . constructor as typeof EngineInstance ) . setupRegistry ( this . __registry__ , options ) ;
175177 }
176178
177- /**
178- Unregister a factory.
179-
180- Overrides `RegistryProxy#unregister` in order to clear any cached instances
181- of the unregistered factory.
182-
183- @public
184- @method unregister
185- @param {String } fullName
186- */
187- unregister ( fullName : FullName ) {
188- this . __container__ . reset ( fullName ) ;
189-
190- // We overwrote this method from RegistryProxyMixin.
191- this . __registry__ . unregister ( fullName ) ;
192- }
193-
194179 /**
195180 Build a new `EngineInstance` that's a child of this instance.
196181
@@ -288,6 +273,92 @@ class EngineInstance
288273
289274 return super . destroy ( ) ;
290275 }
276+
277+ // Registry Proxy
278+ // Duplicated with Engine
279+
280+ declare __registry__ : Registry ;
281+
282+ resolveRegistration ( fullName : string ) {
283+ assert ( 'fullName must be a proper full name' , this . __registry__ . isValidFullName ( fullName ) ) ;
284+ return this . __registry__ . resolve ( fullName ) ;
285+ }
286+
287+ /**
288+ Registers a factory for later injection.
289+
290+ @private
291+ @method register
292+ @param {String } fullName
293+ @param {Function } factory
294+ @param {Object } options
295+ */
296+ register < T extends object , C extends FactoryClass | object > (
297+ fullName : FullName ,
298+ factory : InternalFactory < T , C > ,
299+ options : RegisterOptions & { instantiate : true }
300+ ) : void ;
301+ register ( fullName : FullName , factory : object , options ?: RegisterOptions ) : void ;
302+ register ( ...args : Parameters < Registry [ 'register' ] > ) {
303+ return this . __registry__ . register ( ...args ) ;
304+ }
305+
306+ /**
307+ Unregister a factory.
308+
309+ Also clears any cached instances of the unregistered factory.
310+
311+ @public
312+ @method unregister
313+ @param {String } fullName
314+ */
315+ unregister ( fullName : FullName ) {
316+ this . __container__ . reset ( fullName ) ;
317+
318+ // We overwrote this method from RegistryProxyMixin.
319+ this . __registry__ . unregister ( fullName ) ;
320+ }
321+
322+ /**
323+ Given a fullName check if the registry is aware of its factory
324+ or singleton instance.
325+
326+ @private
327+ @method hasRegistration
328+ @param {String } fullName
329+ @param {Object } [options]
330+ @param {String } [options.source] the fullname of the request source (used for local lookups)
331+ @return {Boolean }
332+ */
333+ hasRegistration ( fullName : FullName ) : boolean {
334+ return this . __registry__ . has ( fullName ) ;
335+ }
336+
337+ registeredOption < K extends keyof RegisterOptions > (
338+ fullName : FullName ,
339+ optionName : K
340+ ) : RegisterOptions [ K ] | undefined {
341+ return this . __registry__ . getOption ( fullName , optionName ) ;
342+ }
343+
344+ registerOptions ( fullName : FullName , options : RegisterOptions ) {
345+ return this . __registry__ . options ( fullName , options ) ;
346+ }
347+
348+ registeredOptions ( fullName : FullName ) : RegisterOptions | undefined {
349+ return this . __registry__ . getOptions ( fullName ) ;
350+ }
351+
352+ /**
353+ Allow registering options for all factories of a type.
354+ */
355+ registerOptionsForType ( type : string , options : RegisterOptions ) {
356+ return this . __registry__ . optionsForType ( type , options ) ;
357+ }
358+
359+ registeredOptionsForType ( type : string ) : RegisterOptions | undefined {
360+ return this . __registry__ . getOptionsForType ( type ) ;
361+ }
291362}
292363
293364// MEGAHAX: This is really nasty, but if we don't define the functions this way, we need to provide types.
0 commit comments