You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
import AbstractFactory from './AbstractFactory.ts'
|
|
import {DependencyRequirement} from '../type/DependencyRequirement.ts'
|
|
import {Collection} from '../../../lib/src/collection/Collection.ts'
|
|
|
|
/**
|
|
* Container factory that produces an item by calling the token as a function.
|
|
* @extends AbstractFactory
|
|
*/
|
|
export default class FunctionFactory extends AbstractFactory {
|
|
constructor(
|
|
/**
|
|
* The name identifying this factory in the container.
|
|
* @type {string}
|
|
*/
|
|
protected name: string,
|
|
|
|
/**
|
|
* The token, which is a function that returns the value of this factory.
|
|
* @type {function}
|
|
*/
|
|
protected token: () => any,
|
|
) {
|
|
super(token)
|
|
}
|
|
|
|
get_dependency_keys(): Collection<DependencyRequirement> {
|
|
return new Collection<DependencyRequirement>()
|
|
}
|
|
|
|
match(something: any) {
|
|
return something === this.name
|
|
}
|
|
|
|
produce(dependencies: any[], parameters: any[]): any {
|
|
return this.token()
|
|
}
|
|
}
|