Start JSDocs
This commit is contained in:
@@ -1,12 +1,38 @@
|
||||
import {Collection} from '../../../lib/src/collection/Collection.ts'
|
||||
import {DependencyRequirement} from '../type/DependencyRequirement.ts'
|
||||
|
||||
/**
|
||||
* Abstract base class for dependency container factories.
|
||||
* @abstract
|
||||
*/
|
||||
export default abstract class AbstractFactory {
|
||||
protected constructor(
|
||||
/**
|
||||
* Token that was registered for this factory. In most cases, this is the static
|
||||
* form of the item that is to be produced by this factory.
|
||||
* @var
|
||||
* @protected
|
||||
*/
|
||||
protected token: any
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Produce an instance of the token.
|
||||
* @param {Array} dependencies - the resolved dependencies, in order
|
||||
* @param {Array} parameters - the bound constructor parameters, in order
|
||||
*/
|
||||
abstract produce(dependencies: any[], parameters: any[]): any
|
||||
|
||||
/**
|
||||
* Should return true if the given identifier matches the token for this factory.
|
||||
* @param something
|
||||
* @return boolean
|
||||
*/
|
||||
abstract match(something: any): boolean
|
||||
|
||||
/**
|
||||
* Get the dependency requirements required by this factory's token.
|
||||
* @return Collection<DependencyRequirement>
|
||||
*/
|
||||
abstract get_dependency_keys(): Collection<DependencyRequirement>
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ import { Collection } from '../../../lib/src/collection/Collection.ts'
|
||||
import { DependencyRequirement } from '../type/DependencyRequirement.ts'
|
||||
import AbstractFactory from './AbstractFactory.ts'
|
||||
|
||||
/**
|
||||
* Standard factory that produces injected versions of instantiable classes.
|
||||
* @extends AbstractFactory
|
||||
*/
|
||||
export default class Factory extends AbstractFactory {
|
||||
constructor(
|
||||
protected token: Instantiable<any>
|
||||
|
||||
@@ -2,9 +2,22 @@ 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)
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
import Factory from './Factory.ts'
|
||||
import Instantiable from "../type/Instantiable.ts";
|
||||
import Instantiable from '../type/Instantiable.ts'
|
||||
|
||||
/**
|
||||
* Container factory that produces an instance of the token, however the token
|
||||
* is identified by a string name rather than a class reference.
|
||||
* @extends Factory
|
||||
*/
|
||||
export default class NamedFactory extends Factory {
|
||||
constructor(
|
||||
/**
|
||||
* The name identifying this factory in the container.
|
||||
* @type {string}
|
||||
*/
|
||||
protected name: string,
|
||||
|
||||
/**
|
||||
* The token to be instantiated.
|
||||
* @type {Instantiable}
|
||||
*/
|
||||
protected token: Instantiable<any>,
|
||||
) {
|
||||
super(token)
|
||||
|
||||
@@ -2,9 +2,24 @@ import Factory from './Factory.ts'
|
||||
import {Collection} from '../../../lib/src/collection/Collection.ts'
|
||||
import {DependencyRequirement} from '../type/DependencyRequirement.ts'
|
||||
|
||||
/**
|
||||
* Container factory which returns its token as its value, without attempting
|
||||
* to instantiate anything. This is used to register already-produced-singletons
|
||||
* with the container.
|
||||
* @extends Factory
|
||||
*/
|
||||
export default class SingletonFactory extends Factory {
|
||||
constructor(
|
||||
/**
|
||||
* Instantiated value of this factory.
|
||||
* @type FunctionConstructor
|
||||
*/
|
||||
protected token: FunctionConstructor,
|
||||
|
||||
/**
|
||||
* String name of this singleton identifying it in the container.
|
||||
* @type string
|
||||
*/
|
||||
protected key: string,
|
||||
) {
|
||||
super(token)
|
||||
|
||||
Reference in New Issue
Block a user