Comparing version 1.0.10 to 1.0.11
import BaseDefinition from "../definitions/BaseDefinition"; | ||
import DIContainer from "../DIContainer"; | ||
import { IDIContainer } from "../DIContainer"; | ||
/** | ||
@@ -9,3 +9,3 @@ * Represents already defined dependency | ||
constructor(existingDefinitionName: string); | ||
resolve: <T>(container: DIContainer, parentDeps?: string[]) => T; | ||
resolve: <T>(container: IDIContainer, parentDeps?: string[]) => T; | ||
} |
import BaseDefinition from "../definitions/BaseDefinition"; | ||
import DIContainer, { IDIContainer } from "../DIContainer"; | ||
import { IDIContainer } from "../DIContainer"; | ||
export declare type Factory = (container: IDIContainer) => any; | ||
@@ -10,3 +10,3 @@ /** | ||
constructor(factory: Factory); | ||
resolve: <T>(container: DIContainer) => T; | ||
resolve: <T>(container: IDIContainer, _parentDeps?: string[] | undefined) => T; | ||
} |
@@ -20,2 +20,3 @@ "use strict"; | ||
var BaseDefinition_1 = __importDefault(require("../definitions/BaseDefinition")); | ||
var errors_1 = require("../errors"); | ||
/** | ||
@@ -28,5 +29,8 @@ * Factory definition - custom function to resolve dependency | ||
var _this = _super.call(this) || this; | ||
_this.resolve = function (container) { | ||
_this.resolve = function (container, _parentDeps) { | ||
return _this.factory(container); | ||
}; | ||
if (typeof factory !== "function") { | ||
throw new errors_1.FactoryDefinitionError(); | ||
} | ||
_this.factory = factory; | ||
@@ -33,0 +37,0 @@ return _this; |
@@ -27,4 +27,3 @@ "use strict"; | ||
var BaseDefinition_1 = __importDefault(require("../definitions/BaseDefinition")); | ||
var MethodIsMissingError_1 = __importDefault(require("../errors/MethodIsMissingError")); | ||
var InvalidConstructorError_1 = __importDefault(require("../errors/InvalidConstructorError")); | ||
var errors_1 = require("../errors"); | ||
/** | ||
@@ -52,3 +51,3 @@ * Definition to create object by provided class name | ||
if (object[methodName] === undefined) { | ||
throw new MethodIsMissingError_1.default(object.constructor.name, methodName); | ||
throw new errors_1.MethodIsMissingError(object.constructor.name, methodName); | ||
} | ||
@@ -66,3 +65,3 @@ var resolvedArgs = args.map(function (arg) { | ||
if (typeof constructorFunction !== "function") { | ||
throw new InvalidConstructorError_1.default(); | ||
throw new errors_1.InvalidConstructorError(); | ||
} | ||
@@ -69,0 +68,0 @@ _this.constructorFunction = constructorFunction; |
@@ -13,6 +13,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var DependencyIsMissingError_1 = __importDefault(require("./errors/DependencyIsMissingError")); | ||
var BaseDefinition_1 = __importDefault(require("./definitions/BaseDefinition")); | ||
var ValueDefinition_1 = __importDefault(require("./definitions/ValueDefinition")); | ||
var CircularDependencyError_1 = __importDefault(require("./errors/CircularDependencyError")); | ||
var errors_1 = require("./errors"); | ||
/** | ||
@@ -34,6 +33,6 @@ * Dependency injection container | ||
if (!(name in this.definitions)) { | ||
throw new DependencyIsMissingError_1.default(name); | ||
throw new errors_1.DependencyIsMissingError(name); | ||
} | ||
if (parentDeps.includes(name)) { | ||
throw new CircularDependencyError_1.default(name, parentDeps); | ||
throw new errors_1.CircularDependencyError(name, parentDeps); | ||
} | ||
@@ -44,3 +43,5 @@ if (this.resolved[name] !== undefined) { | ||
var definition = this.definitions[name]; | ||
this.resolved[name] = definition.resolve(this, __spreadArrays(parentDeps, [name])); | ||
this.resolved[name] = definition.resolve(this, __spreadArrays(parentDeps, [ | ||
name, | ||
])); | ||
return this.resolved[name]; | ||
@@ -47,0 +48,0 @@ }; |
{ | ||
"name": "rsdi", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "dependency injection container", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -78,3 +78,3 @@ # Dependency Injection Container | ||
More details thoughts in my [blog article](https://medium.com/@radzserg/https-medium-com-radzserg-dependency-injection-in-react-part-1-c1decd9c2e7a) | ||
More details thoughts in the [blog article](https://radzserg.medium.com/https-medium-com-radzserg-dependency-injection-in-react-part-2-995e93b3327c) | ||
@@ -81,0 +81,0 @@ ## Usage |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
33959
32
495