Skip to content

Commit 990fb41

Browse files
committed
Kill RegistryProxy Mixin
1 parent 545f883 commit 990fb41

File tree

11 files changed

+192
-111
lines changed

11 files changed

+192
-111
lines changed

broccoli/amd-compat-entrypoints/ember.debug.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ d('@ember/-internals/runtime/index', emberinternalsRuntimeIndex);
5656
import * as emberinternalsRuntimeLibExtRsvp from '@ember/-internals/runtime/lib/ext/rsvp';
5757
d('@ember/-internals/runtime/lib/ext/rsvp', emberinternalsRuntimeLibExtRsvp);
5858

59-
import * as emberinternalsRuntimeLibMixinsRegistryProxy from '@ember/-internals/runtime/lib/mixins/registry_proxy';
60-
d(
61-
'@ember/-internals/runtime/lib/mixins/registry_proxy',
62-
emberinternalsRuntimeLibMixinsRegistryProxy
63-
);
64-
6559
import * as emberinternalsStringIndex from '@ember/-internals/string/index';
6660
d('@ember/-internals/string/index', emberinternalsStringIndex);
6761

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@
205205
"@ember/-internals/routing/index.js": "ember-source/@ember/-internals/routing/index.js",
206206
"@ember/-internals/runtime/index.js": "ember-source/@ember/-internals/runtime/index.js",
207207
"@ember/-internals/runtime/lib/ext/rsvp.js": "ember-source/@ember/-internals/runtime/lib/ext/rsvp.js",
208-
"@ember/-internals/runtime/lib/mixins/registry_proxy.js": "ember-source/@ember/-internals/runtime/lib/mixins/registry_proxy.js",
209208
"@ember/-internals/string/index.js": "ember-source/@ember/-internals/string/index.js",
210209
"@ember/-internals/utility-types/index.js": "ember-source/@ember/-internals/utility-types/index.js",
211210
"@ember/-internals/utils/index.js": "ember-source/@ember/-internals/utils/index.js",
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export { default as RegistryProxyMixin } from './lib/mixins/registry_proxy';
2-
31
export { default as RSVP, onerrorDefault } from './lib/ext/rsvp'; // just for side effect of extending Ember.RSVP

packages/@ember/-internals/runtime/lib/mixins/registry_proxy.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

packages/@ember/engine/index.ts

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import EngineInstance from '@ember/engine/instance';
1414
import { RoutingService } from '@ember/routing/-internals';
1515
import { ComponentLookup } from '@ember/-internals/views';
1616
import { setupEngineRegistry } from '@ember/-internals/glimmer';
17-
import { RegistryProxyMixin } from '@ember/-internals/runtime';
17+
import type { FullName, RegisterOptions } from '@ember/owner';
18+
import type { FactoryClass, InternalFactory } from '@ember/-internals/owner';
1819

1920
function props(obj: object) {
2021
let properties = [];
@@ -50,12 +51,9 @@ export interface Initializer<T> {
5051
5152
@class Engine
5253
@extends Ember.Namespace
53-
@uses RegistryProxyMixin
5454
@public
5555
*/
56-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
57-
interface Engine extends RegistryProxyMixin {}
58-
class Engine extends Namespace.extend(RegistryProxyMixin) {
56+
class Engine extends Namespace {
5957
static initializers: Record<string, Initializer<Engine>> = Object.create(null);
6058
static instanceInitializers: Record<string, Initializer<EngineInstance>> = Object.create(null);
6159

@@ -443,6 +441,79 @@ class Engine extends Namespace.extend(RegistryProxyMixin) {
443441

444442
graph.topsort(cb);
445443
}
444+
445+
// Registry Proxy
446+
// Duplicated with EngineInstance
447+
448+
declare __registry__: Registry;
449+
450+
resolveRegistration(fullName: string) {
451+
assert('fullName must be a proper full name', this.__registry__.isValidFullName(fullName));
452+
return this.__registry__.resolve(fullName);
453+
}
454+
455+
register<T extends object, C extends FactoryClass | object>(
456+
fullName: FullName,
457+
factory: InternalFactory<T, C>,
458+
options: RegisterOptions & { instantiate: true }
459+
): void;
460+
register(fullName: FullName, factory: object, options?: RegisterOptions): void;
461+
register<T extends object, C extends FactoryClass | object>(
462+
fullName: FullName,
463+
factory: InternalFactory<T, C>,
464+
options?: RegisterOptions
465+
): void;
466+
register(...args: Parameters<Registry['register']>) {
467+
return this.__registry__.register(...args);
468+
}
469+
470+
/**
471+
Unregister a fullName
472+
*/
473+
unregister(fullName: FullName) {
474+
this.__registry__.unregister(fullName);
475+
}
476+
477+
/**
478+
Given a fullName check if the registry is aware of its factory
479+
or singleton instance.
480+
481+
@private
482+
@method hasRegistration
483+
@param {String} fullName
484+
@param {Object} [options]
485+
@param {String} [options.source] the fullname of the request source (used for local lookups)
486+
@return {Boolean}
487+
*/
488+
hasRegistration(fullName: FullName): boolean {
489+
return this.__registry__.has(fullName);
490+
}
491+
492+
registeredOption<K extends keyof RegisterOptions>(
493+
fullName: FullName,
494+
optionName: K
495+
): RegisterOptions[K] | undefined {
496+
return this.__registry__.getOption(fullName, optionName);
497+
}
498+
499+
registerOptions(fullName: FullName, options: RegisterOptions) {
500+
return this.__registry__.options(fullName, options);
501+
}
502+
503+
registeredOptions(fullName: FullName): RegisterOptions | undefined {
504+
return this.__registry__.getOptions(fullName);
505+
}
506+
507+
/**
508+
Allow registering options for all factories of a type.
509+
*/
510+
registerOptionsForType(type: string, options: RegisterOptions) {
511+
return this.__registry__.optionsForType(type, options);
512+
}
513+
514+
registeredOptionsForType(type: string): RegisterOptions | undefined {
515+
return this.__registry__.getOptionsForType(type);
516+
}
446517
}
447518

448519
/**

packages/@ember/engine/instance.ts

Lines changed: 96 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ import type { Container } from '@ember/-internals/container';
1010
import { Registry, privatize as P } from '@ember/-internals/container';
1111
import { guidFor } from '@ember/-internals/utils';
1212
import { 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';
1520
import type Owner from '@ember/-internals/owner';
1621
import { type FullName, isFactory } from '@ember/-internals/owner';
1722
import 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.

packages/@ember/engine/type-tests/index.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { ResolverClass } from '@ember/-internals/container/lib/registry';
2-
import type { default as Owner, RegisterOptions, Factory } from '@ember/owner';
2+
import type { default as Owner, RegisterOptions } from '@ember/owner';
33
import type Namespace from '@ember/application/namespace';
44
import type { Initializer } from '@ember/engine';
55
import Engine from '@ember/engine';
66
import type EngineInstance from '@ember/engine/instance';
77
import EmberObject from '@ember/object';
88
import { expectTypeOf } from 'expect-type';
9+
import { InternalFactory } from '@ember/-internals/owner';
910

1011
declare let owner: Owner;
1112

@@ -37,7 +38,8 @@ expectTypeOf(engine.Resolver).toEqualTypeOf<ResolverClass>();
3738
// RegistryProxy
3839

3940
expectTypeOf(engine.resolveRegistration('foo:bar')).toEqualTypeOf<
40-
Factory<object> | object | undefined
41+
// NOTE: The original tests had Factory here. It seems like Factory should match InternalFactory...
42+
InternalFactory<object> | object | undefined
4143
>();
4244
// @ts-expect-error Requires name
4345
engine.resolveRegistration();

packages/ember/barrel.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
sendEvent as emberSendEvent,
4242
} from '@ember/object/events';
4343

44-
import { RegistryProxyMixin, RSVP as _RSVP } from '@ember/-internals/runtime';
44+
import { RSVP as _RSVP } from '@ember/-internals/runtime';
4545
import {
4646
componentCapabilities,
4747
modifierCapabilities,
@@ -160,9 +160,6 @@ namespace Ember {
160160
export const hasListeners = metal.hasListeners;
161161
export const libraries = metal.libraries;
162162

163-
// ****@ember/-internals/runtime****
164-
export const _RegistryProxyMixin = RegistryProxyMixin;
165-
166163
// ****@ember/-internals/view****
167164
export const ComponentLookup = views.ComponentLookup;
168165
export const EventDispatcher = views.EventDispatcher;

0 commit comments

Comments
 (0)