Skip to content
This repository was archived by the owner on Apr 21, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { ... } from 'https://deno.land/x/lambda_ioc@[VERSION]/lambda-ioc/deno/in
```ts
import {
cc2ic, // Stands for "class-constructor to interface-constructor"
constructor,
createContainer,
func
} from '@coderspirit/lambda-ioc'
Expand All @@ -64,10 +63,8 @@ const container = createContainer()
.registerValue('someName', 'Timmy')
// We can register functions
.register('fn', func(printNameAndAge, 'someName', 'someAge'))
// And constructors too
.register('Person', constructor(Person, 'someAge', 'someName'))
// We can do that directly, without having import `constructor`:
.registerConstructor('AnotherPerson', Person, 'someAge', 'someName')
// And constructors too:
.registerConstructor('Person', Person, 'someAge', 'someName')
// In case we want to register a "concrete" constructor to provide an
// abstract interface, we'll have to apply a small hack, using `cc2ic`:
.registerConstructor('Human', cc2ic<Human>()(Person), 'someAge', 'someName')
Expand Down Expand Up @@ -96,14 +93,6 @@ container.resolveGroup('group2') // ~ [3, 4], not necessarily in the same order
// up to date. This is useful if we want to use the container as a factory for
// some of your dependencies.
const resolvedContainer = container.resolve('$')

// If you want to indirectly resolve the container itself, it can be done only
// with the methods:
// - registerConstructor
// - registerAsyncConstructor
// This is because they have "privileged" information about the container's
// type, while relying on `register` or `registerAsync` plus "combinators" does
// not allow us to leverage that information.
```

It is also possible to register and resolve asynchronous factories and
Expand Down
15 changes: 2 additions & 13 deletions lambda-ioc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { ... } from 'https://deno.land/x/lambda_ioc@[VERSION]/lambda-ioc/deno/in
```ts
import {
cc2ic, // Stands for "class-constructor to interface-constructor"
constructor,
createContainer,
func
} from '@coderspirit/lambda-ioc'
Expand All @@ -64,10 +63,8 @@ const container = createContainer()
.registerValue('someName', 'Timmy')
// We can register functions
.register('fn', func(printNameAndAge, 'someName', 'someAge'))
// And constructors too
.register('Person', constructor(Person, 'someAge', 'someName'))
// We can do that directly, without having import `constructor`:
.registerConstructor('AnotherPerson', Person, 'someAge', 'someName')
// And constructors too:
.registerConstructor('Person', Person, 'someAge', 'someName')
// In case we want to register a "concrete" constructor to provide an
// abstract interface, we'll have to apply a small hack, using `cc2ic`:
.registerConstructor('Human', cc2ic<Human>()(Person), 'someAge', 'someName')
Expand Down Expand Up @@ -96,14 +93,6 @@ container.resolveGroup('group2') // ~ [3, 4], not necessarily in the same order
// up to date. This is useful if we want to use the container as a factory for
// some of your dependencies.
const resolvedContainer = container.resolve('$')

// If you want to indirectly resolve the container itself, it can be done only
// with the methods:
// - registerConstructor
// - registerAsyncConstructor
// This is because they have "privileged" information about the container's
// type, while relying on `register` or `registerAsync` plus "combinators" does
// not allow us to leverage that information.
```

It is also possible to register and resolve asynchronous factories and
Expand Down
26 changes: 0 additions & 26 deletions lambda-ioc/deno/combinators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,6 @@ export function func<
}
}

/**
* Given a class constructor, and a list of named dependencies, creates a new
* dependency factory that will resolve a new instance of the class.
*/
export function constructor<
TParams extends readonly unknown[],
TClass,
TDependencies extends ParamsToResolverKeys<TParams>,
>(
constructor: new (...args: TParams) => Awaited<TClass>,
...args: TDependencies
): SyncDependencyFactory<TClass, SyncFuncContainer<TParams, TDependencies>> {
return (container: SyncFuncContainer<TParams, TDependencies>) => {
const resolvedArgs = args.map((arg) =>
container.resolve(
// This is ugly as hell, but I did not want to apply ts-ignore
arg as Parameters<
SyncFuncContainer<TParams, TDependencies>['resolve']
>[0],
),
) as unknown as TParams

return new constructor(...resolvedArgs)
}
}

// Class-Constructor to Interface-Constructor
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function cc2ic<I>(): <CC extends new (...args: any[]) => I>(cc: CC) => AsInterfaceCtor<I, CC> {
Expand Down
1 change: 0 additions & 1 deletion lambda-ioc/deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export {
export {
asyncSingleton,
cc2ic,
constructor,
func,
singleton,
} from './combinators.ts';
2 changes: 1 addition & 1 deletion lambda-ioc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coderspirit/lambda-ioc",
"version": "0.8.0",
"version": "1.0.0",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/cjs/index.d.ts",
Expand Down
41 changes: 0 additions & 41 deletions lambda-ioc/src/__tests__/constructor.test.ts

This file was deleted.

26 changes: 0 additions & 26 deletions lambda-ioc/src/combinators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,6 @@ export function func<
}
}

/**
* Given a class constructor, and a list of named dependencies, creates a new
* dependency factory that will resolve a new instance of the class.
*/
export function constructor<
TParams extends readonly unknown[],
TClass,
TDependencies extends ParamsToResolverKeys<TParams>,
>(
constructor: new (...args: TParams) => Awaited<TClass>,
...args: TDependencies
): SyncDependencyFactory<TClass, SyncFuncContainer<TParams, TDependencies>> {
return (container: SyncFuncContainer<TParams, TDependencies>) => {
const resolvedArgs = args.map((arg) =>
container.resolve(
// This is ugly as hell, but I did not want to apply ts-ignore
arg as Parameters<
SyncFuncContainer<TParams, TDependencies>['resolve']
>[0],
),
) as unknown as TParams

return new constructor(...resolvedArgs)
}
}

// Class-Constructor to Interface-Constructor
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function cc2ic<I>(): <CC extends new (...args: any[]) => I>(cc: CC) => AsInterfaceCtor<I, CC> {
Expand Down
1 change: 0 additions & 1 deletion lambda-ioc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export {
export {
asyncSingleton,
cc2ic,
constructor,
func,
singleton,
} from './combinators'