-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
More TS #19964
Changes from all commits
8539f04
cd40a6b
d62c509
2485aba
c857f97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||||
|
@@ -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 = /^[^:]+:[^:]+$/; | ||||
|
@@ -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; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like it is probably incorrect. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.)
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>; | ||||
|
@@ -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; | ||||
|
@@ -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); | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂 Love it.