Skip to content

Commit

Permalink
feat: set default deps when call 'inject'
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Jul 28, 2020
1 parent bbd97a4 commit edfb3b0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
3 changes: 0 additions & 3 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ test('integration', () => {
({ child, print }, a: number, b: number, c: number) => print(child(a, b, c))
)

const printInjected = parentFn.inject({ print: data => data })
expect(printInjected(2, 3, 4)).toBe((2 + 3) * 4)

const childInjected = parentFn.inject({
child: child.inject({ grandchild: grandchild.inject({ add: (a, b) => a * b }) }),
print: data => data
Expand Down
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ export const depend = <T extends Record<string, any>, U extends [] | [any, ...an
cb: (deps: T, ...params: U) => V
) => {
const fn = (...args: U) => cb(dependencies, ...args)
fn.inject = (partialDeps?: Partial<T>) => {
const deps = { ...dependencies, ...partialDeps }
return (...args: U) => cb(deps, ...args)
}
fn.inject = (deps = dependencies) => (...args: U) => cb(deps, ...args)
return fn
}

0 comments on commit edfb3b0

Please sign in to comment.