Import other modules into monorepo
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
43
src/di/factory/ClosureFactory.ts
Normal file
43
src/di/factory/ClosureFactory.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import {AbstractFactory} from "./AbstractFactory";
|
||||
import {DependencyRequirement, PropertyDependency, StaticClass} from "../types";
|
||||
import {Collection} from "../../util";
|
||||
|
||||
/**
|
||||
* A factory whose token is produced by calling a function.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* let i = 0
|
||||
* const fact = new ClosureFactory('someName', () => {
|
||||
* i += 1
|
||||
* return i * 2
|
||||
* })
|
||||
*
|
||||
* fact.produce([], []) // => 2
|
||||
* fact.produce([], []) // => 4
|
||||
* ```
|
||||
*/
|
||||
export class ClosureFactory extends AbstractFactory {
|
||||
constructor(
|
||||
protected readonly name: string | StaticClass<any, any>,
|
||||
protected readonly token: () => any,
|
||||
) {
|
||||
super(token)
|
||||
}
|
||||
|
||||
produce(dependencies: any[], parameters: any[]): any {
|
||||
return this.token()
|
||||
}
|
||||
|
||||
match(something: any) {
|
||||
return something === this.name
|
||||
}
|
||||
|
||||
getDependencyKeys(): Collection<DependencyRequirement> {
|
||||
return new Collection<DependencyRequirement>()
|
||||
}
|
||||
|
||||
getInjectedProperties(): Collection<PropertyDependency> {
|
||||
return new Collection<PropertyDependency>()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user