Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More TS #19964

Merged
merged 5 commits into from
Feb 24, 2022
Merged

More TS #19964

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3144,7 +3144,7 @@ Clearly, `component-a` has subscribed to `some-other-component`'s `action`. Prev
* CollectionView context is now its content
* Various enhancements to bound helpers: adds multiple property support to bound helpers, adds bind-able options hash properties, adds {{unbound}} helper support to render unbound form of helpers.
* Add App.inject
* Add Ember.EnumberableUtils.intersection
* Add Ember.EnumerableUtils.intersection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 Love it.

* Deprecate Controller#controllerFor in favor of Controller#needs
* Adds `bubbles` property to Ember.TextField
* Allow overriding of Ember.Router#handleURL
Expand Down
15 changes: 5 additions & 10 deletions packages/@ember/-internals/container/lib/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,10 @@ function factoryFor(
return manager;
}

interface FactoryOptions {
instantiate?: boolean;
singleton?: boolean;
}

function isSingletonClass(
container: Container,
fullName: string,
{ instantiate, singleton }: FactoryOptions
{ instantiate, singleton }: TypeOptions
) {
return (
singleton !== false &&
Expand All @@ -329,7 +324,7 @@ function isSingletonClass(
function isSingletonInstance(
container: Container,
fullName: string,
{ instantiate, singleton }: FactoryOptions
{ instantiate, singleton }: TypeOptions
) {
return (
singleton !== false &&
Expand All @@ -342,7 +337,7 @@ function isSingletonInstance(
function isFactoryClass(
container: Container,
fullname: string,
{ instantiate, singleton }: FactoryOptions
{ instantiate, singleton }: TypeOptions
) {
return (
instantiate === false &&
Expand All @@ -354,7 +349,7 @@ function isFactoryClass(
function isFactoryInstance(
container: Container,
fullName: string,
{ instantiate, singleton }: FactoryOptions
{ instantiate, singleton }: TypeOptions
) {
return (
instantiate !== false &&
Expand All @@ -367,7 +362,7 @@ function instantiateFactory(
container: Container,
normalizedName: string,
fullName: string,
options: FactoryOptions
options: TypeOptions
) {
let factoryManager = factoryFor(container, normalizedName, fullName);

Expand Down
26 changes: 12 additions & 14 deletions packages/@ember/-internals/container/lib/registry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Factory } from '@ember/-internals/owner';
import { dictionary, intern } from '@ember/-internals/utils';
import { assert, deprecate } from '@ember/debug';
import { set } from '@ember/object';
import { DEBUG } from '@glimmer/env';
import Container, { ContainerOptions, LazyInjection } from './container';

export interface Injection {
property: string;
specifier: string;
Expand Down Expand Up @@ -36,28 +36,22 @@ export interface IRegistry {
resolve<T, C>(fullName: string, options?: ResolveOptions): Factory<T, C> | undefined;
}

export type NotResolver = {
knownForType: never;
lookupDescription: never;
makeToString: never;
normalize: never;
resolve: never;
};

export type Resolve = <T, C>(name: string) => Factory<T, C> | undefined;
export interface ResolverClass {
create(...args: unknown[]): Resolver;
}

export interface Resolver {
knownForType?: (type: string) => KnownForTypeResult;
lookupDescription?: (fullName: string) => string;
makeToString?: <T, C>(factory: Factory<T, C>, fullName: string) => string;
normalize?: (fullName: string) => string;
resolve: Resolve;
resolve<T, C>(name: string): Factory<T, C> | undefined;
}

export interface RegistryOptions {
fallback?: IRegistry;
registrations?: { [key: string]: object };
resolver?: Resolver | (Resolve & NotResolver);
resolver?: Resolver;
}

const VALID_FULL_NAME_REGEXP = /^[^:]+:[^:]+$/;
Expand All @@ -77,7 +71,7 @@ const VALID_FULL_NAME_REGEXP = /^[^:]+:[^:]+$/;
*/
export default class Registry implements IRegistry {
readonly _failSet: Set<string>;
resolver: Resolver | (Resolve & NotResolver) | null;
resolver: Resolver | null;
Copy link
Member Author

@wagenet wagenet Feb 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it is probably incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting how it works on line 64, are we sure it's not right? (It's certainly weird, and I don't know the runtime code here at all so I'll defer to you on the judgment call.)

resolver?: Resolver | (Resolve & NotResolver);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably deserves a more careful look at least!

readonly fallback: IRegistry | null;
readonly registrations: Record<string, object>;
_localLookupCache: Record<string, object>;
Expand All @@ -86,6 +80,8 @@ export default class Registry implements IRegistry {
readonly _resolveCache: Record<string, object>;
readonly _typeOptions: Record<string, TypeOptions>;

set?: typeof set;

constructor(options: RegistryOptions = {}) {
this.fallback = options.fallback || null;
this.resolver = options.resolver || null;
Expand Down Expand Up @@ -182,7 +178,9 @@ export default class Registry implements IRegistry {
@param {Function} factory
@param {Object} options
*/
register(fullName: string, factory: Factory<unknown>, options: TypeOptions = {}): void {
register(fullName: string, factory: object, options: TypeOptions & { instantiate: false }): void;
register(fullName: string, factory: Factory<unknown>, options?: TypeOptions): void;
register(fullName: string, factory: object, options: TypeOptions = {}): void {
assert('fullName must be a proper full name', this.isValidFullName(fullName));
assert(`Attempting to register an unknown factory: '${fullName}'`, factory !== undefined);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { classify, dasherize } from '@ember/string';
import { A as emberA, typeOf, Namespace, Object as EmberObject } from '@ember/-internals/runtime';
import { getOwner } from '@ember/-internals/owner';
import {
A as emberA,
typeOf,
Namespace,
Object as EmberObject,
NativeArray,
} from '@ember/-internals/runtime';
import { getOwner, Owner } from '@ember/-internals/owner';
import { Resolver } from '@ember/-internals/container/lib/registry';

/**
@module @ember/debug
Expand Down Expand Up @@ -40,23 +47,22 @@ import { getOwner } from '@ember/-internals/owner';
@since 1.5.0
@public
*/
export default EmberObject.extend({
init() {
this._super(...arguments);
export default class ContainerDebugAdapter extends EmberObject {
constructor(owner: Owner) {
super(owner);

this.resolver = getOwner(this).lookup('resolver-for-debugging:main');
},
this.resolver = getOwner(this)!.lookup('resolver-for-debugging:main') as Resolver;
}

/**
The resolver instance of the application
being debugged. This property will be injected
on creation.

@property resolver
@default null
@public
*/
resolver: null,
resolver: Resolver;

/**
Returns true if it is possible to catalog a list of available
Expand All @@ -67,13 +73,13 @@ export default EmberObject.extend({
@return {boolean} whether a list is available for this type.
@public
*/
canCatalogEntriesByType(type) {
canCatalogEntriesByType(type: string) {
if (type === 'model' || type === 'template') {
return false;
}

return true;
},
}

/**
Returns the available classes a given type.
Expand All @@ -83,9 +89,9 @@ export default EmberObject.extend({
@return {Array} An array of strings.
@public
*/
catalogEntriesByType(type) {
catalogEntriesByType(type: string): NativeArray<string> {
let namespaces = emberA(Namespace.NAMESPACES);
let types = emberA();
let types = emberA<string>();
let typeSuffixRegex = new RegExp(`${classify(type)}$`);

namespaces.forEach((namespace) => {
Expand All @@ -102,5 +108,5 @@ export default EmberObject.extend({
}
});
return types;
},
});
}
}
Loading