@wendellhu/redi
Advanced tools
Comparing version 0.13.4 to 0.14.0
@@ -33,2 +33,8 @@ (function (global, factory) { | ||
} | ||
function isExistingDependencyItem(thing) { | ||
if (thing && typeof thing.useExisting !== 'undefined') { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function isAsyncDependencyItem(thing) { | ||
@@ -910,3 +916,3 @@ if (thing && typeof thing.useAsync !== 'undefined') { | ||
this.ensureInjectorNotDisposed(); | ||
return this._resolveClass.apply(this, __spreadArray([ctor], customArgs, false)); | ||
return this._resolveClassImpl.apply(this, __spreadArray([ctor], customArgs, false)); | ||
}; | ||
@@ -922,9 +928,12 @@ Injector.prototype.resolveDependency = function (id, item, shouldCache) { | ||
else if (isFactoryDependencyItem(item)) { | ||
result = this.resolveFactory(id, item, shouldCache); | ||
result = this._resolveFactory(id, item, shouldCache); | ||
} | ||
else if (isClassDependencyItem(item)) { | ||
result = this.resolveClass(id, item, shouldCache); | ||
result = this._resolveClass(id, item, shouldCache); | ||
} | ||
else if (isExistingDependencyItem(item)) { | ||
result = this._resolveExisting(id, item); | ||
} | ||
else { | ||
result = this.resolveAsync(id, item); | ||
result = this._resolveAsync(id, item); | ||
} | ||
@@ -939,2 +948,7 @@ popupResolvingStack(); | ||
}; | ||
Injector.prototype._resolveExisting = function (id, item) { | ||
var thing = this.get(item.useExisting); | ||
this.resolvedDependencyCollection.add(id, thing); | ||
return thing; | ||
}; | ||
Injector.prototype._resolveValueDependency = function (id, item) { | ||
@@ -945,3 +959,3 @@ var thing = item.useValue; | ||
}; | ||
Injector.prototype.resolveClass = function (id, item, shouldCache) { | ||
Injector.prototype._resolveClass = function (id, item, shouldCache) { | ||
var _this = this; | ||
@@ -952,3 +966,3 @@ if (shouldCache === void 0) { shouldCache = true; } | ||
if (item.lazy) { | ||
var idle_1 = new IdleValue(function () { return _this._resolveClass(ctor); }); | ||
var idle_1 = new IdleValue(function () { return _this._resolveClassImpl(ctor); }); | ||
thing = new Proxy(Object.create(null), { | ||
@@ -985,3 +999,3 @@ get: function (target, key) { | ||
else { | ||
thing = this._resolveClass(ctor); | ||
thing = this._resolveClassImpl(ctor); | ||
} | ||
@@ -993,3 +1007,3 @@ if (id && shouldCache) { | ||
}; | ||
Injector.prototype._resolveClass = function (ctor) { | ||
Injector.prototype._resolveClassImpl = function (ctor) { | ||
var extraParams = []; | ||
@@ -1036,3 +1050,3 @@ for (var _i = 1; _i < arguments.length; _i++) { | ||
}; | ||
Injector.prototype.resolveFactory = function (id, item, shouldCache) { | ||
Injector.prototype._resolveFactory = function (id, item, shouldCache) { | ||
var _a; | ||
@@ -1063,11 +1077,11 @@ this.markNewResolution(id); | ||
}; | ||
Injector.prototype.resolveAsync = function (id, item) { | ||
Injector.prototype._resolveAsync = function (id, item) { | ||
var _this = this; | ||
var asyncLoader = { | ||
__symbol: AsyncHookSymbol, | ||
whenReady: function () { return _this._resolveAsync(id, item); }, | ||
whenReady: function () { return _this._resolveAsyncImpl(id, item); }, | ||
}; | ||
return asyncLoader; | ||
}; | ||
Injector.prototype._resolveAsync = function (id, item) { | ||
Injector.prototype._resolveAsyncImpl = function (id, item) { | ||
var _this = this; | ||
@@ -1092,3 +1106,3 @@ return item.useAsync().then(function (thing) { | ||
else if (isCtor(thing)) { | ||
ret = _this._resolveClass(thing); | ||
ret = _this._resolveClassImpl(thing); | ||
} | ||
@@ -1095,0 +1109,0 @@ else { |
@@ -30,2 +30,12 @@ import { DependencyIdentifier } from './dependencyIdentifier'; | ||
export declare function isValueDependencyItem<T>(thing: unknown): thing is ValueDependencyItem<T>; | ||
/** | ||
* Reuse an existing dependency. You can consider it as an alias to another dependency. | ||
*/ | ||
export interface ExistingDependencyItem<T> extends DependencyItemHooks<T> { | ||
/** | ||
* The identifier of the existing dependency. | ||
*/ | ||
useExisting: DependencyIdentifier<T>; | ||
} | ||
export declare function isExistingDependencyItem<T>(thing: unknown): thing is ExistingDependencyItem<T>; | ||
export interface AsyncDependencyItem<T> extends DependencyItemHooks<T> { | ||
@@ -41,4 +51,4 @@ useAsync: () => Promise<T | Ctor<T> | [DependencyIdentifier<T>, SyncDependencyItem<T>]>; | ||
export declare function isAsyncHook<T>(thing: unknown): thing is AsyncHook<T>; | ||
export type SyncDependencyItem<T> = ClassDependencyItem<T> | FactoryDependencyItem<T> | ValueDependencyItem<T>; | ||
export type SyncDependencyItem<T> = ClassDependencyItem<T> | FactoryDependencyItem<T> | ExistingDependencyItem<T> | ValueDependencyItem<T>; | ||
export type DependencyItem<T> = SyncDependencyItem<T> | AsyncDependencyItem<T>; | ||
export declare function prettyPrintIdentifier<T>(id: DependencyIdentifier<T>): string; |
@@ -23,2 +23,8 @@ import { IdentifierDecoratorSymbol, } from './dependencyIdentifier'; | ||
} | ||
export function isExistingDependencyItem(thing) { | ||
if (thing && typeof thing.useExisting !== 'undefined') { | ||
return true; | ||
} | ||
return false; | ||
} | ||
export function isAsyncDependencyItem(thing) { | ||
@@ -25,0 +31,0 @@ if (thing && typeof thing.useAsync !== 'undefined') { |
@@ -86,8 +86,9 @@ import { Dependency, DependencyOrInstance } from './dependencyCollection'; | ||
private resolveDependency; | ||
private _resolveExisting; | ||
private _resolveValueDependency; | ||
private resolveClass; | ||
private _resolveClass; | ||
private resolveFactory; | ||
private resolveAsync; | ||
private _resolveClassImpl; | ||
private _resolveFactory; | ||
private _resolveAsync; | ||
private _resolveAsyncImpl; | ||
private getValue; | ||
@@ -94,0 +95,0 @@ private createDependency; |
@@ -40,3 +40,3 @@ var __extends = (this && this.__extends) || (function () { | ||
import { normalizeForwardRef } from './dependencyForwardRef'; | ||
import { isAsyncDependencyItem, isAsyncHook, isClassDependencyItem, isCtor, isFactoryDependencyItem, isValueDependencyItem, prettyPrintIdentifier, AsyncHookSymbol, } from './dependencyItem'; | ||
import { isAsyncDependencyItem, isAsyncHook, isClassDependencyItem, isCtor, isFactoryDependencyItem, isValueDependencyItem, prettyPrintIdentifier, AsyncHookSymbol, isExistingDependencyItem, } from './dependencyItem'; | ||
import { RediError } from './error'; | ||
@@ -299,3 +299,3 @@ import { IdleValue } from './idleValue'; | ||
this.ensureInjectorNotDisposed(); | ||
return this._resolveClass.apply(this, __spreadArray([ctor], customArgs, false)); | ||
return this._resolveClassImpl.apply(this, __spreadArray([ctor], customArgs, false)); | ||
}; | ||
@@ -311,9 +311,12 @@ Injector.prototype.resolveDependency = function (id, item, shouldCache) { | ||
else if (isFactoryDependencyItem(item)) { | ||
result = this.resolveFactory(id, item, shouldCache); | ||
result = this._resolveFactory(id, item, shouldCache); | ||
} | ||
else if (isClassDependencyItem(item)) { | ||
result = this.resolveClass(id, item, shouldCache); | ||
result = this._resolveClass(id, item, shouldCache); | ||
} | ||
else if (isExistingDependencyItem(item)) { | ||
result = this._resolveExisting(id, item); | ||
} | ||
else { | ||
result = this.resolveAsync(id, item); | ||
result = this._resolveAsync(id, item); | ||
} | ||
@@ -328,2 +331,7 @@ popupResolvingStack(); | ||
}; | ||
Injector.prototype._resolveExisting = function (id, item) { | ||
var thing = this.get(item.useExisting); | ||
this.resolvedDependencyCollection.add(id, thing); | ||
return thing; | ||
}; | ||
Injector.prototype._resolveValueDependency = function (id, item) { | ||
@@ -334,3 +342,3 @@ var thing = item.useValue; | ||
}; | ||
Injector.prototype.resolveClass = function (id, item, shouldCache) { | ||
Injector.prototype._resolveClass = function (id, item, shouldCache) { | ||
var _this = this; | ||
@@ -341,3 +349,3 @@ if (shouldCache === void 0) { shouldCache = true; } | ||
if (item.lazy) { | ||
var idle_1 = new IdleValue(function () { return _this._resolveClass(ctor); }); | ||
var idle_1 = new IdleValue(function () { return _this._resolveClassImpl(ctor); }); | ||
thing = new Proxy(Object.create(null), { | ||
@@ -374,3 +382,3 @@ get: function (target, key) { | ||
else { | ||
thing = this._resolveClass(ctor); | ||
thing = this._resolveClassImpl(ctor); | ||
} | ||
@@ -382,3 +390,3 @@ if (id && shouldCache) { | ||
}; | ||
Injector.prototype._resolveClass = function (ctor) { | ||
Injector.prototype._resolveClassImpl = function (ctor) { | ||
var extraParams = []; | ||
@@ -425,3 +433,3 @@ for (var _i = 1; _i < arguments.length; _i++) { | ||
}; | ||
Injector.prototype.resolveFactory = function (id, item, shouldCache) { | ||
Injector.prototype._resolveFactory = function (id, item, shouldCache) { | ||
var _a; | ||
@@ -452,11 +460,11 @@ this.markNewResolution(id); | ||
}; | ||
Injector.prototype.resolveAsync = function (id, item) { | ||
Injector.prototype._resolveAsync = function (id, item) { | ||
var _this = this; | ||
var asyncLoader = { | ||
__symbol: AsyncHookSymbol, | ||
whenReady: function () { return _this._resolveAsync(id, item); }, | ||
whenReady: function () { return _this._resolveAsyncImpl(id, item); }, | ||
}; | ||
return asyncLoader; | ||
}; | ||
Injector.prototype._resolveAsync = function (id, item) { | ||
Injector.prototype._resolveAsyncImpl = function (id, item) { | ||
var _this = this; | ||
@@ -481,3 +489,3 @@ return item.useAsync().then(function (thing) { | ||
else if (isCtor(thing)) { | ||
ret = _this._resolveClass(thing); | ||
ret = _this._resolveClassImpl(thing); | ||
} | ||
@@ -484,0 +492,0 @@ else { |
@@ -27,2 +27,8 @@ var IdentifierDecoratorSymbol = Symbol('$$IDENTIFIER_DECORATOR'); | ||
} | ||
function isExistingDependencyItem(thing) { | ||
if (thing && typeof thing.useExisting !== 'undefined') { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function isAsyncDependencyItem(thing) { | ||
@@ -904,3 +910,3 @@ if (thing && typeof thing.useAsync !== 'undefined') { | ||
this.ensureInjectorNotDisposed(); | ||
return this._resolveClass.apply(this, __spreadArray([ctor], customArgs, false)); | ||
return this._resolveClassImpl.apply(this, __spreadArray([ctor], customArgs, false)); | ||
}; | ||
@@ -916,9 +922,12 @@ Injector.prototype.resolveDependency = function (id, item, shouldCache) { | ||
else if (isFactoryDependencyItem(item)) { | ||
result = this.resolveFactory(id, item, shouldCache); | ||
result = this._resolveFactory(id, item, shouldCache); | ||
} | ||
else if (isClassDependencyItem(item)) { | ||
result = this.resolveClass(id, item, shouldCache); | ||
result = this._resolveClass(id, item, shouldCache); | ||
} | ||
else if (isExistingDependencyItem(item)) { | ||
result = this._resolveExisting(id, item); | ||
} | ||
else { | ||
result = this.resolveAsync(id, item); | ||
result = this._resolveAsync(id, item); | ||
} | ||
@@ -933,2 +942,7 @@ popupResolvingStack(); | ||
}; | ||
Injector.prototype._resolveExisting = function (id, item) { | ||
var thing = this.get(item.useExisting); | ||
this.resolvedDependencyCollection.add(id, thing); | ||
return thing; | ||
}; | ||
Injector.prototype._resolveValueDependency = function (id, item) { | ||
@@ -939,3 +953,3 @@ var thing = item.useValue; | ||
}; | ||
Injector.prototype.resolveClass = function (id, item, shouldCache) { | ||
Injector.prototype._resolveClass = function (id, item, shouldCache) { | ||
var _this = this; | ||
@@ -946,3 +960,3 @@ if (shouldCache === void 0) { shouldCache = true; } | ||
if (item.lazy) { | ||
var idle_1 = new IdleValue(function () { return _this._resolveClass(ctor); }); | ||
var idle_1 = new IdleValue(function () { return _this._resolveClassImpl(ctor); }); | ||
thing = new Proxy(Object.create(null), { | ||
@@ -979,3 +993,3 @@ get: function (target, key) { | ||
else { | ||
thing = this._resolveClass(ctor); | ||
thing = this._resolveClassImpl(ctor); | ||
} | ||
@@ -987,3 +1001,3 @@ if (id && shouldCache) { | ||
}; | ||
Injector.prototype._resolveClass = function (ctor) { | ||
Injector.prototype._resolveClassImpl = function (ctor) { | ||
var extraParams = []; | ||
@@ -1030,3 +1044,3 @@ for (var _i = 1; _i < arguments.length; _i++) { | ||
}; | ||
Injector.prototype.resolveFactory = function (id, item, shouldCache) { | ||
Injector.prototype._resolveFactory = function (id, item, shouldCache) { | ||
var _a; | ||
@@ -1057,11 +1071,11 @@ this.markNewResolution(id); | ||
}; | ||
Injector.prototype.resolveAsync = function (id, item) { | ||
Injector.prototype._resolveAsync = function (id, item) { | ||
var _this = this; | ||
var asyncLoader = { | ||
__symbol: AsyncHookSymbol, | ||
whenReady: function () { return _this._resolveAsync(id, item); }, | ||
whenReady: function () { return _this._resolveAsyncImpl(id, item); }, | ||
}; | ||
return asyncLoader; | ||
}; | ||
Injector.prototype._resolveAsync = function (id, item) { | ||
Injector.prototype._resolveAsyncImpl = function (id, item) { | ||
var _this = this; | ||
@@ -1086,3 +1100,3 @@ return item.useAsync().then(function (thing) { | ||
else if (isCtor(thing)) { | ||
ret = _this._resolveClass(thing); | ||
ret = _this._resolveClassImpl(thing); | ||
} | ||
@@ -1089,0 +1103,0 @@ else { |
{ | ||
"$schema": "https://raw.githubusercontent.com/wzhudev/squirrel/master/src/schema/package.schema.json", | ||
"name": "@wendellhu/redi", | ||
"version": "0.13.4", | ||
"version": "0.14.0", | ||
"description": "A dependency library for TypeScript and JavaScript, along with a binding for React.", | ||
@@ -6,0 +6,0 @@ "author": "Wenzhao Hu<wzhudev@gmail.com>", |
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
471839
4808