Skip to content

Commit

Permalink
feat: support new features from @wroud/di
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroud committed Nov 18, 2024
1 parent e2d5d35 commit 3261b86
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/@wroud/di-react/src/useService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { SingleServiceType } from "@wroud/di/types";
import { useServiceIterator } from "./useServiceIterator.js";
import { single } from "@wroud/di";

export function useService<T>(type: SingleServiceType<T>): T {
return useServiceIterator(type);
return useServiceIterator(single(type));
}
8 changes: 3 additions & 5 deletions packages/@wroud/di-react/src/useServiceIterator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { useServiceProvider } from "./useServiceProvider.js";
import { ServiceProvider } from "@wroud/di/di/ServiceProvider.js";
import type { ServiceType, SingleServiceType } from "@wroud/di/types";
import type { IResolverServiceType } from "@wroud/di/types";

export function useServiceIterator<T>(type: SingleServiceType<T>): T;
export function useServiceIterator<T>(type: SingleServiceType<T>[]): T[];
export function useServiceIterator<T>(type: ServiceType<T>): T | T[] {
export function useServiceIterator<T>(type: IResolverServiceType<any, T>): T {
const provider = useServiceProvider();

let result: IteratorResult<Promise<unknown>, T | T[]>;
let result: IteratorResult<Promise<unknown>, T>;
const iterator = ServiceProvider.internalGetService(
provider,
type,
Expand Down
3 changes: 2 additions & 1 deletion packages/@wroud/di-react/src/useServices.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { SingleServiceType } from "@wroud/di/types";
import { useServiceIterator } from "./useServiceIterator.js";
import { all } from "@wroud/di";

export function useServices<T>(type: SingleServiceType<T>): T[] {
return useServiceIterator([type]);
return useServiceIterator(all(type));
}

0 comments on commit 3261b86

Please sign in to comment.