Skip to content
This repository was archived by the owner on Apr 21, 2024. It is now read-only.

Commit 26f94f7

Browse files
committed
feat!: remove constructor combinator
The constructor combinator is no loger useful, as `registerConstructor` is much more flexible and powerful, and having both of them adds too much redundancy and weight to the library.
1 parent 568554b commit 26f94f7

File tree

8 files changed

+5
-122
lines changed

8 files changed

+5
-122
lines changed

README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { ... } from 'https://deno.land/x/lambda_ioc@[VERSION]/lambda-ioc/deno/in
3838
```ts
3939
import {
4040
cc2ic, // Stands for "class-constructor to interface-constructor"
41-
constructor,
4241
createContainer,
4342
func
4443
} from '@coderspirit/lambda-ioc'
@@ -64,10 +63,8 @@ const container = createContainer()
6463
.registerValue('someName', 'Timmy')
6564
// We can register functions
6665
.register('fn', func(printNameAndAge, 'someName', 'someAge'))
67-
// And constructors too
68-
.register('Person', constructor(Person, 'someAge', 'someName'))
69-
// We can do that directly, without having import `constructor`:
70-
.registerConstructor('AnotherPerson', Person, 'someAge', 'someName')
66+
// And constructors too:
67+
.registerConstructor('Person', Person, 'someAge', 'someName')
7168
// In case we want to register a "concrete" constructor to provide an
7269
// abstract interface, we'll have to apply a small hack, using `cc2ic`:
7370
.registerConstructor('Human', cc2ic<Human>()(Person), 'someAge', 'someName')
@@ -96,14 +93,6 @@ container.resolveGroup('group2') // ~ [3, 4], not necessarily in the same order
9693
// up to date. This is useful if we want to use the container as a factory for
9794
// some of your dependencies.
9895
const resolvedContainer = container.resolve('$')
99-
100-
// If you want to indirectly resolve the container itself, it can be done only
101-
// with the methods:
102-
// - registerConstructor
103-
// - registerAsyncConstructor
104-
// This is because they have "privileged" information about the container's
105-
// type, while relying on `register` or `registerAsync` plus "combinators" does
106-
// not allow us to leverage that information.
10796
```
10897

10998
It is also possible to register and resolve asynchronous factories and

lambda-ioc/README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { ... } from 'https://deno.land/x/lambda_ioc@[VERSION]/lambda-ioc/deno/in
3838
```ts
3939
import {
4040
cc2ic, // Stands for "class-constructor to interface-constructor"
41-
constructor,
4241
createContainer,
4342
func
4443
} from '@coderspirit/lambda-ioc'
@@ -64,10 +63,8 @@ const container = createContainer()
6463
.registerValue('someName', 'Timmy')
6564
// We can register functions
6665
.register('fn', func(printNameAndAge, 'someName', 'someAge'))
67-
// And constructors too
68-
.register('Person', constructor(Person, 'someAge', 'someName'))
69-
// We can do that directly, without having import `constructor`:
70-
.registerConstructor('AnotherPerson', Person, 'someAge', 'someName')
66+
// And constructors too:
67+
.registerConstructor('Person', Person, 'someAge', 'someName')
7168
// In case we want to register a "concrete" constructor to provide an
7269
// abstract interface, we'll have to apply a small hack, using `cc2ic`:
7370
.registerConstructor('Human', cc2ic<Human>()(Person), 'someAge', 'someName')
@@ -96,14 +93,6 @@ container.resolveGroup('group2') // ~ [3, 4], not necessarily in the same order
9693
// up to date. This is useful if we want to use the container as a factory for
9794
// some of your dependencies.
9895
const resolvedContainer = container.resolve('$')
99-
100-
// If you want to indirectly resolve the container itself, it can be done only
101-
// with the methods:
102-
// - registerConstructor
103-
// - registerAsyncConstructor
104-
// This is because they have "privileged" information about the container's
105-
// type, while relying on `register` or `registerAsync` plus "combinators" does
106-
// not allow us to leverage that information.
10796
```
10897

10998
It is also possible to register and resolve asynchronous factories and

lambda-ioc/deno/combinators.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,6 @@ export function func<
8787
}
8888
}
8989

90-
/**
91-
* Given a class constructor, and a list of named dependencies, creates a new
92-
* dependency factory that will resolve a new instance of the class.
93-
*/
94-
export function constructor<
95-
TParams extends readonly unknown[],
96-
TClass,
97-
TDependencies extends ParamsToResolverKeys<TParams>,
98-
>(
99-
constructor: new (...args: TParams) => Awaited<TClass>,
100-
...args: TDependencies
101-
): SyncDependencyFactory<TClass, SyncFuncContainer<TParams, TDependencies>> {
102-
return (container: SyncFuncContainer<TParams, TDependencies>) => {
103-
const resolvedArgs = args.map((arg) =>
104-
container.resolve(
105-
// This is ugly as hell, but I did not want to apply ts-ignore
106-
arg as Parameters<
107-
SyncFuncContainer<TParams, TDependencies>['resolve']
108-
>[0],
109-
),
110-
) as unknown as TParams
111-
112-
return new constructor(...resolvedArgs)
113-
}
114-
}
115-
11690
// Class-Constructor to Interface-Constructor
11791
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11892
export function cc2ic<I>(): <CC extends new (...args: any[]) => I>(cc: CC) => AsInterfaceCtor<I, CC> {

lambda-ioc/deno/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export {
1111
export {
1212
asyncSingleton,
1313
cc2ic,
14-
constructor,
1514
func,
1615
singleton,
1716
} from './combinators.ts';

lambda-ioc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coderspirit/lambda-ioc",
3-
"version": "0.8.0",
3+
"version": "1.0.0",
44
"main": "./dist/cjs/index.js",
55
"module": "./dist/esm/index.js",
66
"types": "./dist/cjs/index.d.ts",

lambda-ioc/src/__tests__/constructor.test.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

lambda-ioc/src/combinators.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,6 @@ export function func<
8787
}
8888
}
8989

90-
/**
91-
* Given a class constructor, and a list of named dependencies, creates a new
92-
* dependency factory that will resolve a new instance of the class.
93-
*/
94-
export function constructor<
95-
TParams extends readonly unknown[],
96-
TClass,
97-
TDependencies extends ParamsToResolverKeys<TParams>,
98-
>(
99-
constructor: new (...args: TParams) => Awaited<TClass>,
100-
...args: TDependencies
101-
): SyncDependencyFactory<TClass, SyncFuncContainer<TParams, TDependencies>> {
102-
return (container: SyncFuncContainer<TParams, TDependencies>) => {
103-
const resolvedArgs = args.map((arg) =>
104-
container.resolve(
105-
// This is ugly as hell, but I did not want to apply ts-ignore
106-
arg as Parameters<
107-
SyncFuncContainer<TParams, TDependencies>['resolve']
108-
>[0],
109-
),
110-
) as unknown as TParams
111-
112-
return new constructor(...resolvedArgs)
113-
}
114-
}
115-
11690
// Class-Constructor to Interface-Constructor
11791
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11892
export function cc2ic<I>(): <CC extends new (...args: any[]) => I>(cc: CC) => AsInterfaceCtor<I, CC> {

lambda-ioc/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export {
1111
export {
1212
asyncSingleton,
1313
cc2ic,
14-
constructor,
1514
func,
1615
singleton,
1716
} from './combinators'

0 commit comments

Comments
 (0)