Skip to content

Commit

Permalink
fix(create-injection-token): allow createNoopInjectionToken pass in i…
Browse files Browse the repository at this point in the history
…sFunctionVAlue
  • Loading branch information
ctran authored and ctran committed Jun 18, 2024
1 parent 1a2702c commit d990892
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type CreateProvideFnOptions<
> = Pick<
CreateInjectionTokenOptions<TFactory, TFactoryDeps>,
'deps' | 'extraProviders' | 'multi'
>;
> & { isFunctionValue?: boolean };

type InjectFn<TFactoryReturn> = {
(): TFactoryReturn;
Expand Down Expand Up @@ -114,7 +114,10 @@ function createProvideFn<
opts: CreateProvideFnOptions<TFactory, TFactoryDeps> = {},
) {
const { deps = [], multi = false, extraProviders = [] } = opts;
return (value?: TValue | (() => TValue), isFunctionValue = false) => {
return (
value?: TValue | (() => TValue),
isFunctionValue = opts.isFunctionValue ?? false,
) => {
let provider: Provider;
if (typeof value !== 'undefined') {
// TODO: (chau) maybe this can be made better
Expand Down Expand Up @@ -251,7 +254,9 @@ export function createNoopInjectionToken<
CreateInjectionTokenOptions<() => void, []>,
'extraProviders'
> &
(TMulti extends true ? { multi: true } : Record<string, never>),
(TMulti extends true ? { multi: true } : Record<string, never>) & {
isFunctionValue?: boolean;
},
>(description: string, options?: TOptions) {
type TReturn = TMulti extends true ? Array<TValue> : TValue;

Expand Down

0 comments on commit d990892

Please sign in to comment.