Skip to content

Commit

Permalink
0.2.2 (#12)
Browse files Browse the repository at this point in the history
* Added Types to Containers (#11)

* 0.2.2
  • Loading branch information
ImOverlord authored Jan 29, 2020
1 parent 9ac9d6d commit d9fb08c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@booster-ts/core",
"version": "0.2.1",
"version": "0.2.2",
"description": "Core Booster DI Library",
"main": "dist/core.js",
"types": "dist/core.d.ts",
Expand Down
14 changes: 7 additions & 7 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ require("reflect-metadata");

type IType<T> = new(...args: Array<any>) => T;

interface IContainer {
interface IContainer<T = any, U = any> {
name: string;
class: any;
data?: any;
target: IType<any>;
class: T;
data?: U;
target: IType<T>;
}

/**
Expand Down Expand Up @@ -138,8 +138,8 @@ export class Injector {
* @description Returns Container with certain key
* @param keyName to find on target
*/
public getContainerByKey(keyName: string): Array<IContainer> {
const containerArray: Array<IContainer> = [];
public getContainerByKey<T = any, U = any>(keyName: string): Array<IContainer<T, U>> {
const containerArray: Array<IContainer<T, U>> = [];
this.container.forEach((container: IContainer) => {
const data = Reflect.getMetadata('data', container.target);
if (data === undefined)
Expand All @@ -158,7 +158,7 @@ export class Injector {
* @param keyName Key to find on Target
* @param value to find on key
*/
public getContainerByValue(keyName: string, value: any): Array<IContainer> {
public getContainerByValue<T = any, U = any>(keyName: string, value: any): Array<IContainer<T, U>> {
const containerArray: Array<IContainer> = [];
this.container.forEach((container: IContainer) => {
const data = Reflect.getMetadata('data', container.target);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe("Basic Injection Test", () => {
injector.register("DependencyF", DependencyF);
injector.register("DependencyA", DependencyA);

const arr = injector.getContainerByValue('type', "plugin");
const arr = injector.getContainerByValue<DependencyF, {type: string}>('type', "plugin");
expect(arr.length).toBe(1);
expect(arr[0].target).toBe(DependencyF);
expect(arr[0].data.type).toBe("plugin");
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"max-line-length": [
true,
{
"limit": 100,
"limit": 150,
"ignore-pattern": "^import |^export {(.*?)}|\/\/"
}
],
Expand Down

0 comments on commit d9fb08c

Please sign in to comment.