Skip to content

Commit

Permalink
refactor: extract bindable interface for containers and modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Evyweb committed Dec 11, 2024
1 parent 82abd62 commit 8d7aef0
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type DependencyArray = DependencyKey[];

export type Scope = 'singleton' | 'transient' | 'scoped';

export interface Container {
interface Bindable {
bind(key: DependencyKey): {
toValue: (value: unknown) => void;
toFunction: (fn: CallableFunction) => void;
Expand All @@ -31,7 +31,9 @@ export interface Container {
scope?: Scope
) => void;
};
}

export interface Container extends Bindable {
load(moduleKey: ModuleKey, module: Module): void;

get<T>(key: DependencyKey): T;
Expand All @@ -41,28 +43,7 @@ export interface Container {
runInScope<T>(callback: () => T): T;
}

export interface Module {
bind(key: DependencyKey): {
toValue: (value: unknown) => void;
toFunction: (fn: CallableFunction) => void;
toHigherOrderFunction: (
fn: CallableFunction,
dependencies?: DependencyArray | DependencyObject,
scope?: Scope
) => void;
toCurry: (
fn: CallableFunction,
dependencies?: DependencyArray | DependencyObject,
scope?: Scope
) => void;
toFactory: (factory: CallableFunction, scope?: Scope) => void;
toClass: <C>(
constructor: new (...args: any[]) => C,
dependencies?: DependencyArray | DependencyObject,
scope?: Scope
) => void;
};

export interface Module extends Bindable {
bindings: Map<DependencyKey, Binding>;
}

Expand Down

0 comments on commit 8d7aef0

Please sign in to comment.