@kaokei/di 1.0.21 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +128 -0
- package/README.md +20 -103
- package/dist/index.cjs.js +450 -233
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +3 -3
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.cjs.runtime.js +444 -229
- package/dist/index.cjs.runtime.js.map +1 -1
- package/dist/index.cjs.runtime.min.js +3 -3
- package/dist/index.cjs.runtime.min.js.map +1 -1
- package/dist/index.esm.js +451 -219
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +4 -4
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.esm.runtime.js +439 -214
- package/dist/index.esm.runtime.js.map +1 -1
- package/dist/index.esm.runtime.min.js +4 -4
- package/dist/index.esm.runtime.min.js.map +1 -1
- package/dist/index.iife.js +457 -237
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +4 -4
- package/dist/index.iife.min.js.map +1 -1
- package/dist/src/Injector.d.ts +67 -32
- package/dist/src/Injector.d.ts.map +1 -1
- package/dist/src/constants.d.ts +5 -11
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/decorator.d.ts +13 -1
- package/dist/src/decorator.d.ts.map +1 -1
- package/dist/src/errors/CircularDependencyError.d.ts +6 -0
- package/dist/src/errors/CircularDependencyError.d.ts.map +1 -0
- package/dist/src/errors/InjectFailedError.d.ts +6 -0
- package/dist/src/errors/InjectFailedError.d.ts.map +1 -0
- package/dist/src/errors/ProviderNotValidError.d.ts +6 -0
- package/dist/src/errors/ProviderNotValidError.d.ts.map +1 -0
- package/dist/src/errors/TokenNotFoundError.d.ts +6 -0
- package/dist/src/errors/TokenNotFoundError.d.ts.map +1 -0
- package/dist/src/errors/index.d.ts +5 -0
- package/dist/src/errors/index.d.ts.map +1 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +5 -7
- package/dist/.DS_Store +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
### [1.0.25](https://github.com/kaokei/di/compare/v1.0.24...v1.0.25) (2021-12-11)
|
|
6
|
+
|
|
7
|
+
### [1.0.24](https://github.com/kaokei/di/compare/v1.0.23...v1.0.24) (2021-12-11)
|
|
8
|
+
|
|
9
|
+
### [1.0.23](https://github.com/kaokei/di/compare/v1.0.22...v1.0.23) (2021-12-10)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **default:** 删除了defaultValue ([7cae1d0](https://github.com/kaokei/di/commit/7cae1d039298b39ec7fccd793a804743ec43ab6c))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **fix:** catch dispose error ([2ee9b4a](https://github.com/kaokei/di/commit/2ee9b4a69158e8a5741144170615beb25c2e84a7))
|
|
20
|
+
* **fix:** 修复了判断InjectFailed场景的错误 ([c97f092](https://github.com/kaokei/di/commit/c97f092744e178236b1317aab108f92d337eb943))
|
|
21
|
+
|
|
22
|
+
### 1.0.22 (2021-10-07)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* **bugfix:** 修复dispose的bug ([eb5116d](https://github.com/kaokei/di/commit/eb5116d28139ad7c21738e089ce764e76609b3c6))
|
|
28
|
+
|
|
29
|
+
### [1.0.21](https://github.com/kaokei/di/compare/v1.0.20...v1.0.21) (2021-09-16)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
* **inject:** 修改Inject的参数是必填项 ([2ec3dbe](https://github.com/kaokei/di/commit/2ec3dbeea8dc02ab0d8b43ce104192626cb8a9dd))
|
|
35
|
+
|
|
36
|
+
### [1.0.20](https://github.com/kaokei/di/compare/v1.0.19...v1.0.20) (2021-08-22)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* **reflect-metadata:** import reflect-metadata ([5e21184](https://github.com/kaokei/di/commit/5e21184f922f32d97640b42c96982313dc5c9ea4))
|
|
42
|
+
|
|
43
|
+
### [1.0.19](https://github.com/kaokei/di/compare/v1.0.18...v1.0.19) (2021-08-22)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Bug Fixes
|
|
47
|
+
|
|
48
|
+
* **fix export:** 重新导出autobind ([ea721c2](https://github.com/kaokei/di/commit/ea721c28be8c0734e43b95a01bc234843346ca5e))
|
|
49
|
+
|
|
50
|
+
### [1.0.18](https://github.com/kaokei/di/compare/v1.0.17...v1.0.18) (2021-08-21)
|
|
51
|
+
|
|
52
|
+
### [1.0.17](https://github.com/kaokei/di/compare/v1.0.16...v1.0.17) (2021-08-21)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Bug Fixes
|
|
56
|
+
|
|
57
|
+
* **autobind:** export autobind ([4f2f4c8](https://github.com/kaokei/di/commit/4f2f4c83bbdb0bcb87bc44df608bdb6fc4858ec2))
|
|
58
|
+
|
|
59
|
+
### [1.0.16](https://github.com/kaokei/di/compare/v1.0.15...v1.0.16) (2021-08-21)
|
|
60
|
+
|
|
61
|
+
### [1.0.15](https://github.com/kaokei/di/compare/v1.0.14...v1.0.15) (2021-08-21)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Features
|
|
65
|
+
|
|
66
|
+
* **autobind:** add autobind-decorator pacakge ([ff60ead](https://github.com/kaokei/di/commit/ff60ead4eb892a15249d8ef74153451c16e0c696))
|
|
67
|
+
|
|
68
|
+
### [1.0.14](https://github.com/kaokei/di/compare/v1.0.13...v1.0.14) (2021-08-06)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Features
|
|
72
|
+
|
|
73
|
+
* **util:** export utils ([458d75e](https://github.com/kaokei/di/commit/458d75e7583d4ca6bfa3c32755daf9b1e1f17b1a))
|
|
74
|
+
|
|
75
|
+
### [1.0.13](https://github.com/kaokei/di/compare/v1.0.12...v1.0.13) (2021-08-06)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### Features
|
|
79
|
+
|
|
80
|
+
* **merge:** 支持mergeHook ([427a1e2](https://github.com/kaokei/di/commit/427a1e2f9681284e579a96a94dce0f4ee96f0414))
|
|
81
|
+
|
|
82
|
+
### [1.0.12](https://github.com/kaokei/di/compare/v1.0.10...v1.0.12) (2021-08-04)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
### Features
|
|
86
|
+
|
|
87
|
+
* **injector:** injector support dispose ([7b1246d](https://github.com/kaokei/di/commit/7b1246d31ad0a621fe7ee6e0b007d621fb28643b))
|
|
88
|
+
|
|
89
|
+
### [1.0.10](https://github.com/kaokei/di/compare/v1.0.9...v1.0.10) (2021-08-03)
|
|
90
|
+
|
|
91
|
+
### [1.0.9](https://github.com/kaokei/di/compare/v1.0.8...v1.0.9) (2021-07-01)
|
|
92
|
+
|
|
93
|
+
### [1.0.8](https://github.com/kaokei/di/compare/v1.0.7...v1.0.8) (2021-06-29)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### Bug Fixes
|
|
97
|
+
|
|
98
|
+
* **package.json:** set reflect-metadata to be peer dependency ([4368411](https://github.com/kaokei/di/commit/4368411ce44d0f0f754c8bf8e3f263e3f27dbed2))
|
|
99
|
+
|
|
100
|
+
### [1.0.7](https://github.com/kaokei/di/compare/v1.0.6...v1.0.7) (2021-06-29)
|
|
101
|
+
|
|
102
|
+
### [1.0.6](https://github.com/kaokei/di/compare/v1.0.5...v1.0.6) (2021-06-29)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
### Bug Fixes
|
|
106
|
+
|
|
107
|
+
* **index:** change location of reflect-metadata ([b7b8e03](https://github.com/kaokei/di/commit/b7b8e033554a3ea4604d3753947be5762e4b9032))
|
|
108
|
+
|
|
109
|
+
### [1.0.5](https://github.com/kaokei/di/compare/v1.0.4...v1.0.5) (2021-06-29)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
### Bug Fixes
|
|
113
|
+
|
|
114
|
+
* **injector:** should return postHook service ([6c73a3e](https://github.com/kaokei/di/commit/6c73a3eb43a6d1670d446fcaaadcd1178ab51fda))
|
|
115
|
+
|
|
116
|
+
### [1.0.4](https://github.com/kaokei/di/compare/v1.0.3...v1.0.4) (2021-06-29)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
### Features
|
|
120
|
+
|
|
121
|
+
* **injector:** add postHook ([db75b02](https://github.com/kaokei/di/commit/db75b02e049017ed959a83e310b3cb96e9514060))
|
|
122
|
+
|
|
123
|
+
### [1.0.3](https://github.com/kaokei/di/compare/v1.0.1...v1.0.3) (2021-06-29)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
### Bug Fixes
|
|
127
|
+
|
|
128
|
+
* **ci:** modify ci name ([b43f69c](https://github.com/kaokei/di/commit/b43f69cbdfe2069f559045a95efc92a956b04d20))
|
package/README.md
CHANGED
|
@@ -1,131 +1,48 @@
|
|
|
1
1
|
<h1 align="center">di</h1>
|
|
2
2
|
<div align="center">
|
|
3
3
|
|
|
4
|
-
[](https://github.com/kaokei/di/actions/workflows/build.yml)
|
|
4
|
+
[](https://github.com/kaokei/di/actions/workflows/build.yml)
|
|
5
|
+
[](https://coveralls.io/github/kaokei/di?branch=main)
|
|
5
6
|
|
|
6
7
|
</div>
|
|
7
8
|
|
|
8
|
-
##
|
|
9
|
+
## 文档
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
- package.json 中的 name,这个大多数时可能就是和项目名一致了,但是如果是带有 scope 的,或者驼峰的,都需要自己修改。
|
|
12
|
-
- package.json 中的 browserVariableName,这个大多数情况下不关心也不会有问题,但是如果我们想要编译的代码想要在浏览器中直接使用,最好是指定一个全局变量。
|
|
13
|
-
- package.json 中的 homepage,bugs-url,repository-url 这些外部链接。
|
|
14
|
-
- README.md 中的 github 地址。
|
|
15
|
-
|
|
16
|
-
## github 地址
|
|
17
|
-
|
|
18
|
-
- [github](https://github.com/kaokei/di)
|
|
11
|
+
[Document](https://www.kaokei.com/project/di/)
|
|
19
12
|
|
|
20
13
|
## 解决了什么问题?
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
## 特性
|
|
25
|
-
|
|
26
|
-
使用 typescript,并且类型定义统一在 types 文件夹中,建议使用 module 来管理类型,而不是 script 来创建全局的类型。
|
|
27
|
-
`tsconfig.json`作为编辑器的默认配置文件,方便编辑器识别。实际构建时使用`tsconfig.app.json`文件
|
|
28
|
-
|
|
29
|
-
使用 esm 模块化规范
|
|
30
|
-
|
|
31
|
-
使用 npm 作为包管理
|
|
32
|
-
|
|
33
|
-
使用 git 作为代码版本工具。
|
|
34
|
-
|
|
35
|
-
编码规范使用 eslint+prettier+editorconfig
|
|
36
|
-
|
|
37
|
-
git commit message 采用 angular 规范,以及使用 commitlint 校验
|
|
38
|
-
|
|
39
|
-
使用 yorkie 自动化校验并格式化代码,自动化校验 commit message
|
|
40
|
-
|
|
41
|
-
使用 jest 作为单元测试,统一放在`tests`文件夹中。
|
|
42
|
-
|
|
43
|
-
可以在 playground 中进行代码实验,使用 vscode 配置.vscode/launch.json 可以调试 nodejs
|
|
44
|
-
|
|
45
|
-
使用 rollup 作为打包工具,同时打包出多个版本的 bundle。支持压缩/未压缩、使用 runtime/不使用 runtime、commonjs/esm、浏览器版本总共 10 个版本。
|
|
46
|
-
|
|
47
|
-
npm run release:first 第一次发布,会自动创建 CHANGELOG.md 文件
|
|
48
|
-
npm run release patch 发布新版本
|
|
49
|
-
|
|
50
|
-
使用 MIT 作为开源协议
|
|
51
|
-
|
|
52
|
-
### 循环依赖
|
|
53
|
-
|
|
54
|
-
一般来讲循环依赖在不同的场景下有不同的含义。
|
|
55
|
-
|
|
56
|
-
举个例子:
|
|
57
|
-
|
|
58
|
-
小明眼睛看不见,小王腿走不了路。所以小明要看书时就需要小王来帮忙。小王要走路的时候就需要小明来帮忙。
|
|
59
|
-
|
|
60
|
-
这个例子中,可以很明显的看出来小明和小王之间是存在互相依赖的。但是这种互相依赖具体是不是循环依赖取决于具体的场景。
|
|
61
|
-
|
|
62
|
-
考虑这样的场景,就是循环依赖了。小明要看书,请求小王帮忙读书,小王说读书可以是可以,但是我一直坐在椅子上,没有力气读书,你背我走一走吧,小明说你先帮我读书,我再被你走路,小王说你先背我走路,我再帮你读书。
|
|
15
|
+
基于 typescript 实现依赖注入能力。类似的目前比较流行的 library 是`InversifyJS`。
|
|
63
16
|
|
|
64
|
-
|
|
17
|
+
其他类似的 library 可以[参考这里](https://github.com/topics/ioc?l=typescript)和[参考这里](https://github.com/topics/dependency-injection?l=typescript)
|
|
65
18
|
|
|
66
|
-
|
|
19
|
+
### playground
|
|
67
20
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
上面说到的“较少”有循环依赖的场景。常见场景有这两个:
|
|
71
|
-
|
|
72
|
-
场景一:A extends B 同时 B extends A,即 extends 关键字会导致循环依赖。
|
|
73
|
-
场景二:@decorator(A) class B {} 同时 @decorator(B) class A {}。装饰器也是立即执行的,也会导致循环依赖。
|
|
74
|
-
|
|
75
|
-
### 对循环依赖的态度
|
|
76
|
-
|
|
77
|
-
业务中应该尽量避免循环依赖,如果实在避免不了,那么就需要仔细分析各个模块之间的依赖关系。需要手动解耦各个模块。使之变为互相依赖。
|
|
78
|
-
|
|
79
|
-
目前的 es6/babel/typescript 都不能直接帮我们解决这种循环依赖,但是应该有相应的提示信息辅助我们发现潜在的循环依赖。
|
|
80
|
-
|
|
81
|
-
### 关于循环依赖的讨论
|
|
82
|
-
|
|
83
|
-
看了半天,总结起来就是问题是客观存在的,只能具体问题具体分析。并不存在一劳永逸的方案。
|
|
84
|
-
|
|
85
|
-
[How to solve this basic ES6-module circular dependency problem?](https://esdiscuss.org/topic/how-to-solve-this-basic-es6-module-circular-dependency-problem)
|
|
86
|
-
|
|
87
|
-
[TypeScript needs to support circular references between classes in separate files.](https://github.com/Microsoft/TypeScript/issues/20361)
|
|
88
|
-
|
|
89
|
-
[Angular 2 Forward Reference](https://segmentfault.com/a/1190000008626276)
|
|
90
|
-
|
|
91
|
-
### 大佬怎么解决循环依赖的
|
|
92
|
-
|
|
93
|
-
我没能复现这种解决方案,感觉并不能解决问题
|
|
94
|
-
|
|
95
|
-
[How to fix nasty circular dependency issues once and for all in JavaScript & TypeScript](https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de)
|
|
96
|
-
|
|
97
|
-
[How to fix this ES6 module circular dependency?](https://stackoverflow.com/questions/38841469/how-to-fix-this-es6-module-circular-dependency)
|
|
98
|
-
|
|
99
|
-
[Known Limitation: Classes as identifiers and circular dependencies](https://github.com/inversify/InversifyJS/blob/master/wiki/classes_as_id.md#known-limitation-classes-as-identifiers-and-circular-dependencies)
|
|
100
|
-
|
|
101
|
-
[InversifyJS Circular dependencies](https://github.com/inversify/InversifyJS/blob/master/wiki/circular_dependencies.md)
|
|
102
|
-
|
|
103
|
-
### 待支持特性
|
|
104
|
-
|
|
105
|
-
- 删除了@DefauleValue,使用 ts 自带的默认参数
|
|
106
|
-
- usePromise
|
|
107
|
-
- 自定义装饰器@Prev @Post
|
|
108
|
-
- postConstruct 代替 onInit
|
|
109
|
-
- LazyInject 看情况-Vue 目前是不需要的
|
|
110
|
-
- middleware
|
|
111
|
-
- 各种 forwardRef
|
|
21
|
+
https://codesandbox.io/s/di-playground-zjnyv
|
|
112
22
|
|
|
113
23
|
### 已经支持的特性
|
|
114
24
|
|
|
115
25
|
- 支持类,Symbol,字符串等作为服务的 token
|
|
116
26
|
- 支持类,值,工厂函数等作为服务
|
|
117
|
-
- Injector 作为 DI 容器,易于测试
|
|
118
27
|
- 支持@Inject、@Skip、@Self、@Optional 以及 forwardRef 控制获取服务
|
|
28
|
+
- 支持@Optional 配置可选注入以及类属性的初始值作为默认值
|
|
29
|
+
- Injector 作为 DI 容器,易于测试
|
|
119
30
|
- 同一个服务在同一个 Injector 中一定是单例的
|
|
120
31
|
- 支持分层 DI 系统
|
|
121
|
-
-
|
|
32
|
+
- 支持属性注入和构造函数注入
|
|
122
33
|
- 支持部分循环依赖,对于不支持的循环依赖会有相应的提示
|
|
123
34
|
- 支持类型提示,以及 InjectionKey 的类型提示
|
|
35
|
+
- 支持 dispose 生命周期钩子
|
|
124
36
|
|
|
125
37
|
### 不支持的特性
|
|
126
38
|
|
|
127
39
|
- 不支持 multi-injection
|
|
128
|
-
- 不支持不能自己 new
|
|
129
|
-
-
|
|
130
|
-
- 没有 InversifyJS 中复杂的 binding 的 API,尽量采用`new Injector([providers])`
|
|
40
|
+
- 不支持不能自己 new 的注入,比如 react 类组件的实例化过程我们干预不了,因为 Injector 容器内部非常重要的一个工作就是 new 一个对象。
|
|
41
|
+
- 对于类的继承没有过多的支持,[参考这里](https://docs.typestack.community/typedi/v/develop/02-basic-usage-guide/07-inheritance)以及[参考这里](https://github.com/inversify/InversifyJS/blob/master/wiki/inheritance.md)
|
|
131
42
|
- 暂时不实现 providers 中使用 forwardRef,主要是不了解使用场景,目前只支持在@Inject 中使用 forwardRef
|
|
43
|
+
- 不支持异步实例化,即该实例对象的状态和数据依赖服务器端数据,需要异步获取,等待获取数据成功之后才实例化对象。对于这种场景建议在实例对象中维护类似 loading/ready/inited 这种字段来表明数据是否准备完毕。
|
|
44
|
+
- 不支持 LazyInject
|
|
45
|
+
- 不支持 onInit 生命周期钩子,虽然 Spring 中时支持的,但是实际场景中并不常用,[参考这里](https://github.com/angular/angular/issues/23235)
|
|
46
|
+
- 不支持自定义装饰器,比如@Prev、@Post 等装饰器,类似 autobind,应该独立维护
|
|
47
|
+
- 原来确实导出了 autobind,后续删除了该导出,有业务需要可以自己 `npm install autobind-decorator` 即可
|
|
48
|
+
- 不支持中间件
|