Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Oct 9, 2024
1 parent add8845 commit f807c09
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
6 changes: 2 additions & 4 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ export const ErrorMessages = {
CircularDependency: 'circular dependency:',
DeferredWithoutInject: 'deferred without Inject:',
InjectOutsideOfContext: 'inject outside of context',
}
} as const

/** @internal */
export function assert(condition: unknown, ...args: any[]): asserts condition {
if (!condition) {
throw new Error(args.join(' '))
}
}

/** @internal */
export function expectNever(value: never): never {
throw new TypeError('Unexpected value: ' + value)
throw new TypeError('unexpected value: ' + value)
}
4 changes: 0 additions & 4 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ import type {InjectionConfig} from './config'
import type {Resolvable} from './resolver'
import type {Constructor} from './token'

/** @internal */
export interface InjectionMetadata<T = any> extends Partial<InjectionConfig<T>> {
injections?: InjectionBindings
deferredInjections?: InjectionCollection
}

/** @internal */
export type InjectionBindings = Map<string | symbol, Injection>

/** @internal */
export type InjectionCollection = Set<Injection>

/** @internal */
export interface Injection<T = any> {
resolvable: Resolvable<T>
getValue(instance: object): T
Expand Down
12 changes: 2 additions & 10 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ export type Resolvable<T> =
| InjectionConfig<T>
| InjectionProvider<T>

/** @internal */
export type ResolvedScope = Exclude<InjectionScope, typeof InjectionScope.Inherited>

/** @internal */
export interface Resolver {
scope: ResolvedScope
stack: InjectionToken[]
Expand All @@ -20,18 +18,12 @@ export interface Resolver {
resolve<T>(resolvable: Resolvable<T>): T
}

/** @internal */
export type ResolverProvider = <T>(resolver: Resolver, callback: ResolverCallback<T>) => T
/** @internal */
export type ResolverCallback<T> = (resolver: Resolver) => T
/** @internal */
export type ResolverConsumer = () => Resolver | null

/** @internal */
function createResolverContext() {
let contextResolver: Resolver | null = null

const withResolver: ResolverProvider = (resolver, callback) => {
const withResolver = <T>(resolver: Resolver, callback: ResolverCallback<T>) => {
const currentResolver = contextResolver
contextResolver = resolver
try {
Expand All @@ -42,7 +34,7 @@ function createResolverContext() {
}
}

const useResolver: ResolverConsumer = () => {
const useResolver = () => {
return contextResolver
}

Expand Down

0 comments on commit f807c09

Please sign in to comment.