Skip to content

Commit

Permalink
Merge pull request #146 from inversify/refactor/update-simplify-bindi…
Browse files Browse the repository at this point in the history
…ng-models

Simplify binding models
  • Loading branch information
notaphplover authored Nov 30, 2024
2 parents 53a25c4 + b492e1c commit fbd9d41
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ describe(stringifyBinding.name, () => {
implementationType: class Foo {},
isSatisfiedBy: () => true,
moduleId: undefined,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
scope: bindingScopeValues.Singleton,
serviceIdentifier: 'service-id',
type: bindingTypeValues.Instance,
Expand All @@ -48,14 +42,8 @@ describe(stringifyBinding.name, () => {
id: 0,
isSatisfiedBy: () => true,
moduleId: undefined,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
scope: bindingScopeValues.Singleton,
serviceIdentifier: 'service-id',
type: bindingTypeValues.ConstantValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export type BindingType =
| 'ConstantValue'
| 'Constructor'
| 'DynamicValue'
| 'Factory'
| 'Instance'
Expand All @@ -9,7 +8,6 @@ export type BindingType =

export const bindingTypeValues: { [TKey in BindingType]: TKey } = {
ConstantValue: 'ConstantValue',
Constructor: 'Constructor',
DynamicValue: 'DynamicValue',
Factory: 'Factory',
Instance: 'Instance',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import { ScopedBinding } from './ScopedBinding';
export type ConstantValueBinding<TActivated> = ScopedBinding<
typeof bindingTypeValues.ConstantValue,
typeof bindingScopeValues.Singleton,
TActivated
TActivated | Promise<TActivated>
>;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface DynamicValueBinding<TActivated>
extends ScopedBinding<
typeof bindingTypeValues.DynamicValue,
BindingScope,
TActivated
TActivated | Promise<TActivated>
> {
readonly value: DynamicValue<TActivated>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface FactoryBinding<TActivated>
extends ScopedBinding<
typeof bindingTypeValues.Factory,
typeof bindingScopeValues.Singleton,
TActivated
Factory<TActivated>
> {
readonly factory: () => Factory<TActivated>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ProviderBinding<TActivated>
extends ScopedBinding<
typeof bindingTypeValues.Provider,
typeof bindingScopeValues.Singleton,
TActivated
Provider<TActivated>
> {
readonly provider: () => Provider<TActivated>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export interface ScopedBinding<
TScope extends BindingScope,
TActivated,
> extends BaseBinding<TType, TActivated> {
readonly cache: Either<undefined, TActivated | Promise<TActivated>>;
readonly onActivation: Either<undefined, BindingActivation<TActivated>>;
readonly onDeactivation: Either<undefined, BindingDeactivation<TActivated>>;
cache: Either<undefined, TActivated>;
readonly onActivation: BindingActivation<TActivated> | undefined;
readonly onDeactivation: BindingDeactivation<TActivated> | undefined;
readonly scope: TScope;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@ describe(BindingServiceImplementation.name, () => {
id: 2,
isSatisfiedBy: (): boolean => true,
moduleId: 1,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
scope: bindingScopeValues.Singleton,
serviceIdentifier: 'service-identifier-fixture',
type: bindingTypeValues.ConstantValue,
Expand Down Expand Up @@ -83,14 +77,8 @@ describe(BindingServiceImplementation.name, () => {
id: 2,
isSatisfiedBy: (): boolean => true,
moduleId: 1,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
scope: bindingScopeValues.Singleton,
serviceIdentifier: Symbol(),
type: bindingTypeValues.ConstantValue,
Expand Down Expand Up @@ -135,14 +123,8 @@ describe(BindingServiceImplementation.name, () => {
id: 2,
isSatisfiedBy: (): boolean => true,
moduleId: 1,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
scope: bindingScopeValues.Singleton,
serviceIdentifier: Symbol(),
type: bindingTypeValues.ConstantValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,8 @@ describe(
id: 1,
isSatisfiedBy: () => true,
moduleId: undefined,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
scope: bindingScopeValues.Singleton,
serviceIdentifier: 'service-id',
type: bindingTypeValues.ConstantValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,8 @@ describe(plan.name, () => {
id: 0,
isSatisfiedBy: () => true,
moduleId: undefined,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
scope: bindingScopeValues.Singleton,
serviceIdentifier: ServiceIds.constantValue,
type: bindingTypeValues.ConstantValue,
Expand All @@ -234,14 +228,8 @@ describe(plan.name, () => {
id: 1,
isSatisfiedBy: () => true,
moduleId: undefined,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
scope: bindingScopeValues.Singleton,
serviceIdentifier: ServiceIds.dynamicValue,
type: bindingTypeValues.DynamicValue,
Expand All @@ -257,14 +245,8 @@ describe(plan.name, () => {
id: 2,
isSatisfiedBy: () => true,
moduleId: undefined,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
scope: bindingScopeValues.Singleton,
serviceIdentifier: ServiceIds.factory,
type: bindingTypeValues.Factory,
Expand All @@ -279,14 +261,8 @@ describe(plan.name, () => {
implementationType: Foo,
isSatisfiedBy: () => true,
moduleId: undefined,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
scope: bindingScopeValues.Singleton,
serviceIdentifier: ServiceIds.instance,
type: bindingTypeValues.Instance,
Expand All @@ -300,14 +276,8 @@ describe(plan.name, () => {
id: 4,
isSatisfiedBy: () => true,
moduleId: undefined,
onActivation: {
isRight: false,
value: undefined,
},
onDeactivation: {
isRight: false,
value: undefined,
},
onActivation: undefined,
onDeactivation: undefined,
provider: () => async () => Symbol(),
scope: bindingScopeValues.Singleton,
serviceIdentifier: ServiceIds.provider,
Expand Down
Loading

0 comments on commit fbd9d41

Please sign in to comment.