@wendellhu/redi
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -326,2 +326,5 @@ (function (global, factory) { | ||
}; | ||
DependencyCollection.prototype.delete = function (id) { | ||
this.dependencyMap.delete(id); | ||
}; | ||
DependencyCollection.prototype.get = function (id, quantity) { | ||
@@ -385,2 +388,9 @@ if (quantity === void 0) { quantity = exports.Quantity.REQUIRED; } | ||
}; | ||
ResolvedDependencyCollection.prototype.delete = function (id) { | ||
if (this.resolvedDependencies.has(id)) { | ||
var things = this.resolvedDependencies.get(id); | ||
things.forEach(function (t) { return (isDisposable(t) ? t.dispose() : void 0); }); | ||
this.resolvedDependencies.delete(id); | ||
} | ||
}; | ||
ResolvedDependencyCollection.prototype.get = function (id, quantity) { | ||
@@ -402,7 +412,3 @@ if (quantity === void 0) { quantity = exports.Quantity.REQUIRED; } | ||
Array.from(this.resolvedDependencies.values()).forEach(function (items) { | ||
items.forEach(function (item) { | ||
if (isDisposable(item)) { | ||
item.dispose(); | ||
} | ||
}); | ||
items.forEach(function (item) { return (isDisposable(item) ? item.dispose() : void 0); }); | ||
}); | ||
@@ -690,2 +696,3 @@ this.resolvedDependencies.clear(); | ||
this.resolvedDependencyCollection.dispose(); | ||
this.deleteThisFromParent(); | ||
this.disposed = true; | ||
@@ -713,2 +720,9 @@ }; | ||
}; | ||
/** | ||
* delete a dependency and instantiated values from an injector | ||
*/ | ||
Injector.prototype.delete = function (id) { | ||
this.dependencyCollection.delete(id); | ||
this.resolvedDependencyCollection.delete(id); | ||
}; | ||
Injector.prototype.get = function (id, quantityOrLookup, lookUp) { | ||
@@ -992,2 +1006,8 @@ var newResult = this._get(id, quantityOrLookup, lookUp); | ||
}; | ||
Injector.prototype.deleteThisFromParent = function () { | ||
if (this.parent) { | ||
var index = this.parent.children.indexOf(this); | ||
this.parent.children.splice(index, 1); | ||
} | ||
}; | ||
return Injector; | ||
@@ -994,0 +1014,0 @@ }()); |
@@ -24,2 +24,3 @@ import { DependencyIdentifier } from './dependencyIdentifier'; | ||
add<T>(id: DependencyIdentifier<T>, val: DependencyItem<T>): void; | ||
delete<T>(id: DependencyIdentifier<T>): void; | ||
get<T>(id: DependencyIdentifier<T>): DependencyItem<T>; | ||
@@ -47,2 +48,3 @@ get<T>(id: DependencyIdentifier<T>, quantity: Quantity.REQUIRED): DependencyItem<T>; | ||
has<T>(id: DependencyIdentifier<T>): boolean; | ||
delete<T>(id: DependencyIdentifier<T>): void; | ||
get<T>(id: DependencyIdentifier<T>): T; | ||
@@ -49,0 +51,0 @@ get<T>(id: DependencyIdentifier<T>, quantity: Quantity.OPTIONAL): T | null; |
@@ -58,2 +58,5 @@ var __extends = (this && this.__extends) || (function () { | ||
}; | ||
DependencyCollection.prototype.delete = function (id) { | ||
this.dependencyMap.delete(id); | ||
}; | ||
DependencyCollection.prototype.get = function (id, quantity) { | ||
@@ -118,2 +121,9 @@ if (quantity === void 0) { quantity = Quantity.REQUIRED; } | ||
}; | ||
ResolvedDependencyCollection.prototype.delete = function (id) { | ||
if (this.resolvedDependencies.has(id)) { | ||
var things = this.resolvedDependencies.get(id); | ||
things.forEach(function (t) { return (isDisposable(t) ? t.dispose() : void 0); }); | ||
this.resolvedDependencies.delete(id); | ||
} | ||
}; | ||
ResolvedDependencyCollection.prototype.get = function (id, quantity) { | ||
@@ -135,7 +145,3 @@ if (quantity === void 0) { quantity = Quantity.REQUIRED; } | ||
Array.from(this.resolvedDependencies.values()).forEach(function (items) { | ||
items.forEach(function (item) { | ||
if (isDisposable(item)) { | ||
item.dispose(); | ||
} | ||
}); | ||
items.forEach(function (item) { return (isDisposable(item) ? item.dispose() : void 0); }); | ||
}); | ||
@@ -142,0 +148,0 @@ this.resolvedDependencies.clear(); |
@@ -19,2 +19,6 @@ import { Dependency, DependencyPair } from './dependencyCollection'; | ||
/** | ||
* delete a dependency and instantiated values from an injector | ||
*/ | ||
delete<T>(id: DependencyIdentifier<T>): void; | ||
/** | ||
* get a dependency | ||
@@ -58,2 +62,3 @@ */ | ||
private ensureInjectorNotDisposed; | ||
private deleteThisFromParent; | ||
} |
@@ -99,2 +99,3 @@ var __extends = (this && this.__extends) || (function () { | ||
this.resolvedDependencyCollection.dispose(); | ||
this.deleteThisFromParent(); | ||
this.disposed = true; | ||
@@ -122,2 +123,9 @@ }; | ||
}; | ||
/** | ||
* delete a dependency and instantiated values from an injector | ||
*/ | ||
Injector.prototype.delete = function (id) { | ||
this.dependencyCollection.delete(id); | ||
this.resolvedDependencyCollection.delete(id); | ||
}; | ||
Injector.prototype.get = function (id, quantityOrLookup, lookUp) { | ||
@@ -401,2 +409,8 @@ var newResult = this._get(id, quantityOrLookup, lookUp); | ||
}; | ||
Injector.prototype.deleteThisFromParent = function () { | ||
if (this.parent) { | ||
var index = this.parent.children.indexOf(this); | ||
this.parent.children.splice(index, 1); | ||
} | ||
}; | ||
return Injector; | ||
@@ -403,0 +417,0 @@ }()); |
@@ -320,2 +320,5 @@ var IdentifierDecoratorSymbol = Symbol('$$IDENTIFIER_DECORATOR'); | ||
}; | ||
DependencyCollection.prototype.delete = function (id) { | ||
this.dependencyMap.delete(id); | ||
}; | ||
DependencyCollection.prototype.get = function (id, quantity) { | ||
@@ -379,2 +382,9 @@ if (quantity === void 0) { quantity = Quantity.REQUIRED; } | ||
}; | ||
ResolvedDependencyCollection.prototype.delete = function (id) { | ||
if (this.resolvedDependencies.has(id)) { | ||
var things = this.resolvedDependencies.get(id); | ||
things.forEach(function (t) { return (isDisposable(t) ? t.dispose() : void 0); }); | ||
this.resolvedDependencies.delete(id); | ||
} | ||
}; | ||
ResolvedDependencyCollection.prototype.get = function (id, quantity) { | ||
@@ -396,7 +406,3 @@ if (quantity === void 0) { quantity = Quantity.REQUIRED; } | ||
Array.from(this.resolvedDependencies.values()).forEach(function (items) { | ||
items.forEach(function (item) { | ||
if (isDisposable(item)) { | ||
item.dispose(); | ||
} | ||
}); | ||
items.forEach(function (item) { return (isDisposable(item) ? item.dispose() : void 0); }); | ||
}); | ||
@@ -684,2 +690,3 @@ this.resolvedDependencies.clear(); | ||
this.resolvedDependencyCollection.dispose(); | ||
this.deleteThisFromParent(); | ||
this.disposed = true; | ||
@@ -707,2 +714,9 @@ }; | ||
}; | ||
/** | ||
* delete a dependency and instantiated values from an injector | ||
*/ | ||
Injector.prototype.delete = function (id) { | ||
this.dependencyCollection.delete(id); | ||
this.resolvedDependencyCollection.delete(id); | ||
}; | ||
Injector.prototype.get = function (id, quantityOrLookup, lookUp) { | ||
@@ -986,2 +1000,8 @@ var newResult = this._get(id, quantityOrLookup, lookUp); | ||
}; | ||
Injector.prototype.deleteThisFromParent = function () { | ||
if (this.parent) { | ||
var index = this.parent.children.indexOf(this); | ||
this.parent.children.splice(index, 1); | ||
} | ||
}; | ||
return Injector; | ||
@@ -988,0 +1008,0 @@ }()); |
{ | ||
"$schema": "https://raw.githubusercontent.com/wendellhu95/squirrel/master/src/schema/package.schema.json", | ||
"name": "@wendellhu/redi", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "A dependency library for TypeScript and JavaScript, along with a binding for React.", | ||
@@ -22,3 +22,3 @@ "exports": { | ||
"peerDependencies": { | ||
"react": "^16.8.0" | ||
"react": ">= 16.8.0" | ||
}, | ||
@@ -25,0 +25,0 @@ "main": "./dist/redi.js", |
@@ -5,7 +5,6 @@ # redi | ||
 | ||
 | ||
 | ||
[](https://codecov.io/gh/wendellhu95/redi) | ||
A dependency library for TypeScript and JavaScript, along with a binding for React. | ||
no | ||
@@ -16,22 +15,35 @@ ## Overview | ||
import { Inject } from '@wendellhu/redi' | ||
class AuthService { | ||
public getCurrentUserInfo(): UserInfo { | ||
// your implementation here... | ||
} | ||
} | ||
class FileListService { | ||
constructor(@Inject(AuthService) private readonly authService: AuthService) {} | ||
public getUserFiles(): Promise<Files> { | ||
const currentUser = this.authService.getCurrentUserInfo() | ||
// ... | ||
} | ||
} | ||
const injector = new Injector([[AuthService], [FileListService]]) | ||
injector.get(AuthService) | ||
``` | ||
**View full documentation and examples on [redi.wendell.fun](https://redi.wendell.fun/).** | ||
**View full documentation on [redi.wendell.fun](https://redi.wendell.fun/).** | ||
## Links | ||
* [Demo TodoMVC](https://wendellhu95.github.io/redi-todomvc/) | [source](https://github.com/wendellhu95/redi-todomvc) | ||
* Doc site [source](https://github.com/wendellhu95/redi-site) | ||
* [scaffold](https://github.com/wendellhu95/redi-starter) | ||
## Users | ||
* Team Lark at ByteDance | ||
## License | ||
MIT. Copyright 2021 Wendell Hu. |
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
383880
3873
48