@composer-js/core
Advanced tools
Comparing version 6.0.0-rc.11 to 6.0.0-rc.12
@@ -21,11 +21,16 @@ "use strict"; | ||
* if no object has been created yet. | ||
* @param type The name or type of the class instance to inject. | ||
* @param name The unique name of the object to inject. Set to `undefined` to force a new instance to be created. Default value is `default`. | ||
* @param args The constructor arguments to use if the object hasn't been created before. | ||
* @param type The fully qualified name or type of the class to instantiate. If a type is given it's class name will be inferred | ||
* via the constructor name. | ||
* @param name The unique name to give the class instance. Set to `undefined` if you wish to force a new object is created. | ||
* @param initialize Set to `true` to initialize the object after creation, otherwise set to `false`. Default is `true`. | ||
* @param args The set of constructor arguments to use during construction | ||
*/ | ||
function Inject(type, name = "default", ...args) { | ||
function Inject(type, options) { | ||
return function (target, propertyKey) { | ||
options = { | ||
...options, | ||
name: options?.name || "default", | ||
}; | ||
Reflect.defineMetadata("cjs:injectObject", { | ||
args, | ||
name, | ||
options, | ||
type, | ||
@@ -32,0 +37,0 @@ }, target, propertyKey); |
@@ -137,3 +137,3 @@ "use strict"; | ||
// Now retrieve the instance for the given name | ||
const instance = await this.newInstance(injectObject.type, injectObject.name, ...injectObject.args); | ||
const instance = await this.newInstance(injectObject.type, injectObject.options); | ||
obj[member] = instance; | ||
@@ -232,3 +232,6 @@ } | ||
*/ | ||
newInstance(type, name = uuid.v4(), initialize = true, ...args) { | ||
newInstance(type, options) { | ||
let name = options?.name || uuid.v4(); | ||
const initialize = options?.initialize !== undefined ? options.initialize : true; | ||
const args = options?.args || []; | ||
// If an class type was given extract it's fqn | ||
@@ -235,0 +238,0 @@ const className = typeof type === "string" ? type : type.fqn || type.name || type.constructor.name; |
import "reflect-metadata"; | ||
import { InstanceOptions } from "../ObjectFactory"; | ||
/** | ||
@@ -9,7 +10,9 @@ * Apply this to a class function to mark it as a destructor to be called by the `ObjectFactory` during cleanup. | ||
* if no object has been created yet. | ||
* @param type The name or type of the class instance to inject. | ||
* @param name The unique name of the object to inject. Set to `undefined` to force a new instance to be created. Default value is `default`. | ||
* @param args The constructor arguments to use if the object hasn't been created before. | ||
* @param type The fully qualified name or type of the class to instantiate. If a type is given it's class name will be inferred | ||
* via the constructor name. | ||
* @param name The unique name to give the class instance. Set to `undefined` if you wish to force a new object is created. | ||
* @param initialize Set to `true` to initialize the object after creation, otherwise set to `false`. Default is `true`. | ||
* @param args The set of constructor arguments to use during construction | ||
*/ | ||
export declare function Inject(type: any, name?: string | undefined, ...args: any): (target: any, propertyKey: string | symbol) => void; | ||
export declare function Inject(type: any, options?: InstanceOptions): (target: any, propertyKey: string | symbol) => void; | ||
/** | ||
@@ -16,0 +19,0 @@ * Apply this to a function to be executed once a new object instance has been created and all dependencies injected. |
import "reflect-metadata"; | ||
/** | ||
* The set of options to use when creating new instances of objects. | ||
*/ | ||
export interface InstanceOptions { | ||
args?: any[]; | ||
name?: string; | ||
initialize?: boolean; | ||
} | ||
/** | ||
* The `ObjectFactory` is a manager for creating objects based on registered | ||
@@ -62,3 +70,3 @@ * class types. This allows for the tracking of multiple instances of objects | ||
*/ | ||
newInstance<T>(type: any, name?: string | null, initialize?: boolean, ...args: any): T | Promise<T>; | ||
newInstance<T>(type: any, options?: InstanceOptions): T | Promise<T>; | ||
/** | ||
@@ -65,0 +73,0 @@ * Registers the given class type for the provided fully qualified name. |
{ | ||
"name": "@composer-js/core", | ||
"version": "6.0.0-rc.11", | ||
"version": "6.0.0-rc.12", | ||
"description": "A collection of common utilities and core functionality for composerjs applications.", | ||
@@ -5,0 +5,0 @@ "repository": "https://gitlab.acceleratxr.com/composerjs/composer-core.git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
214606
3537