From 4cb5c21d40aae66f199d3c06ee17e6e7f81fd097 Mon Sep 17 00:00:00 2001 From: Wenzhao Hu Date: Wed, 31 Jul 2024 20:41:15 +0800 Subject: [PATCH] feat: support has API on accessor (#29) --- package.json | 2 +- src/injector.ts | 10 ++++++++-- tsconfig.json | 5 +---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index f615556..2373f5e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/wzhudev/squirrel/master/src/schema/package.schema.json", "name": "@wendellhu/redi", - "version": "0.16.0", + "version": "0.16.1", "description": "A dependency library for TypeScript and JavaScript, along with a binding for React.", "scripts": { "test": "vitest run", diff --git a/src/injector.ts b/src/injector.ts index bc0bf35..48e5f54 100644 --- a/src/injector.ts +++ b/src/injector.ts @@ -30,7 +30,6 @@ import { AsyncHookSymbol, isExistingDependencyItem, ExistingDependencyItem, - DependencyItemHooks, } from './dependencyItem' import { RediError } from './error' import { IdleValue } from './idleValue' @@ -92,6 +91,7 @@ class DeleteDependencyAfterResolutionError extends RediError { export interface IAccessor { get: Injector['get'] + has: Injector['has'] } /** @@ -254,6 +254,13 @@ export class Injector { ) => { return this._get(id, quantityOrLookup, lookUp) }, + + has: ( + id: DependencyIdentifier + ): boolean => { + return this.has(id) + } + } return cb(accessor, ...args) @@ -447,7 +454,6 @@ export class Injector { item: ClassDependencyItem, shouldCache = true ): T { - const ctor = item.useClass let thing: T if (item.lazy) { diff --git a/tsconfig.json b/tsconfig.json index 9cd0207..f787858 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,9 +24,6 @@ "strictPropertyInitialization": true, "experimentalDecorators": true, "esModuleInterop": true, - "types": [ - "node", - ], "typeRoots": [ "./node_modules/@types" ], @@ -42,4 +39,4 @@ "include": [ "src/**/*", ] -} \ No newline at end of file +}