Skip to content

Commit

Permalink
feat: support has API on accessor (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev authored Jul 31, 2024
1 parent eb6a460 commit 4cb5c21
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 8 additions & 2 deletions src/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
AsyncHookSymbol,
isExistingDependencyItem,
ExistingDependencyItem,
DependencyItemHooks,
} from './dependencyItem'
import { RediError } from './error'
import { IdleValue } from './idleValue'
Expand Down Expand Up @@ -92,6 +91,7 @@ class DeleteDependencyAfterResolutionError<T> extends RediError {

export interface IAccessor {
get: Injector['get']
has: Injector['has']
}

/**
Expand Down Expand Up @@ -254,6 +254,13 @@ export class Injector {
) => {
return this._get(id, quantityOrLookup, lookUp)
},

has: <D>(
id: DependencyIdentifier<D>
): boolean => {
return this.has(id)
}

}

return cb(accessor, ...args)
Expand Down Expand Up @@ -447,7 +454,6 @@ export class Injector {
item: ClassDependencyItem<T>,
shouldCache = true
): T {
const ctor = item.useClass
let thing: T

if (item.lazy) {
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"strictPropertyInitialization": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"types": [
"node",
],
"typeRoots": [
"./node_modules/@types"
],
Expand All @@ -42,4 +39,4 @@
"include": [
"src/**/*",
]
}
}

0 comments on commit 4cb5c21

Please sign in to comment.