-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
92 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Container, Resolvable } from '.'; | ||
interface BindingContract { | ||
resolvable: Resolvable<unknown>; | ||
shared: boolean; | ||
} | ||
declare class Binding implements BindingContract { | ||
resolvable: Resolvable<unknown>; | ||
shared: boolean; | ||
constructor(resolvable: Resolvable<unknown>, shared?: boolean); | ||
resolveInjectables(container: Container): unknown[]; | ||
resolve(container: Container, params?: unknown[]): any; | ||
static isResolvable(binding: unknown): boolean; | ||
static once(resolvable: Resolvable<unknown>, container: Container, params: unknown[]): any; | ||
} | ||
export default Binding; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { Key, Resolvable } from '.'; | ||
export default class Container { | ||
protected bindings: Map<any, any>; | ||
protected instances: Map<any, any>; | ||
protected aliases: Map<any, any>; | ||
/** | ||
* Checks if anything has been bound or aliased into the Container | ||
*/ | ||
has(key: Key): boolean; | ||
/** | ||
* Binds a resolvable function into the Container | ||
* | ||
* If it is the only param, the object reference works as the reference key | ||
*/ | ||
bind(key: Key | Resolvable<unknown>, resolvable?: unknown | Resolvable<unknown>, shared?: boolean): this; | ||
private resolve; | ||
/** | ||
* Resolves a Binding reference from the Container | ||
* | ||
* If the given key is a Resolvable function, | ||
* it is resolved from the Container on the fly | ||
*/ | ||
make(key: unknown, ...params: unknown[]): any; | ||
/** | ||
* Resolves a Binding reference from the Container | ||
*/ | ||
get<T extends new (...p: any[]) => InstanceType<T>>(key: T): InstanceType<T>; | ||
get<T>(key: T): T extends new () => infer I ? I : unknown; | ||
/** | ||
* Set an object or primitive value into the Container | ||
* | ||
* When resolved, it returns the same value and reference | ||
*/ | ||
instance(key: Key, value: unknown): void; | ||
/** | ||
* Bind a Resolvable function into the Container. | ||
* | ||
* The function is resolved once. Its result is stored | ||
* and returned on subsequent calls to `get` or `make`. | ||
*/ | ||
singleton(key: Key, resolvable: unknown): this; | ||
private getInstance; | ||
/** | ||
* Apply an alias to an already-bound binding | ||
*/ | ||
alias(alias: unknown, key: Key | Resolvable<unknown>): void; | ||
private getAlias; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export { default as Container } from './Container'; | ||
export declare type Key = unknown; | ||
export declare type Injectable = { | ||
injects: Array<Resolvable<unknown>>; | ||
}; | ||
export declare type Resolvable<T> = { | ||
(...params: unknown[]): T; | ||
} & { | ||
new (...params: unknown[]): T; | ||
} & T & Injectable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
/* eslint-disable no-use-before-define */ | ||
export { default as Container } from './Container' | ||
|
||
export const a = 2 | ||
|
||
export type Key = unknown | ||
|
||
export type Injectable = { | ||
injects: Array<Resolvable<unknown>> | ||
} | ||
|
||
export type Resolvable<T> = { (...params: unknown[]): T } & { | ||
new (...params: unknown[]): T | ||
} & T & | ||
Injectable |
This file was deleted.
Oops, something went wrong.