@kaokei/di 1.0.18 → 1.0.23

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/README.md +20 -102
  3. package/dist/index.cjs.js +442 -231
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.cjs.min.js +3 -3
  6. package/dist/index.cjs.min.js.map +1 -1
  7. package/dist/index.cjs.runtime.js +436 -227
  8. package/dist/index.cjs.runtime.js.map +1 -1
  9. package/dist/index.cjs.runtime.min.js +3 -3
  10. package/dist/index.cjs.runtime.min.js.map +1 -1
  11. package/dist/index.esm.js +444 -214
  12. package/dist/index.esm.js.map +1 -1
  13. package/dist/index.esm.min.js +4 -4
  14. package/dist/index.esm.min.js.map +1 -1
  15. package/dist/index.esm.runtime.js +432 -209
  16. package/dist/index.esm.runtime.js.map +1 -1
  17. package/dist/index.esm.runtime.min.js +4 -4
  18. package/dist/index.esm.runtime.min.js.map +1 -1
  19. package/dist/index.iife.js +450 -234
  20. package/dist/index.iife.js.map +1 -1
  21. package/dist/index.iife.min.js +4 -4
  22. package/dist/index.iife.min.js.map +1 -1
  23. package/dist/src/Injector.d.ts +61 -27
  24. package/dist/src/Injector.d.ts.map +1 -1
  25. package/dist/src/constants.d.ts +5 -11
  26. package/dist/src/constants.d.ts.map +1 -1
  27. package/dist/src/decorator.d.ts +12 -0
  28. package/dist/src/decorator.d.ts.map +1 -1
  29. package/dist/src/errors/CircularDependencyError.d.ts +6 -0
  30. package/dist/src/errors/CircularDependencyError.d.ts.map +1 -0
  31. package/dist/src/errors/InjectFailedError.d.ts +6 -0
  32. package/dist/src/errors/InjectFailedError.d.ts.map +1 -0
  33. package/dist/src/errors/ProviderNotValidError.d.ts +6 -0
  34. package/dist/src/errors/ProviderNotValidError.d.ts.map +1 -0
  35. package/dist/src/errors/TokenNotFoundError.d.ts +6 -0
  36. package/dist/src/errors/TokenNotFoundError.d.ts.map +1 -0
  37. package/dist/src/errors/index.d.ts +5 -0
  38. package/dist/src/errors/index.d.ts.map +1 -0
  39. package/dist/src/index.d.ts +2 -3
  40. package/dist/src/index.d.ts.map +1 -1
  41. package/package.json +5 -7
package/CHANGELOG.md ADDED
@@ -0,0 +1,124 @@
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.23](https://github.com/kaokei/di/compare/v1.0.22...v1.0.23) (2021-12-10)
6
+
7
+
8
+ ### Features
9
+
10
+ * **default:** 删除了defaultValue ([7cae1d0](https://github.com/kaokei/di/commit/7cae1d039298b39ec7fccd793a804743ec43ab6c))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **fix:** catch dispose error ([2ee9b4a](https://github.com/kaokei/di/commit/2ee9b4a69158e8a5741144170615beb25c2e84a7))
16
+ * **fix:** 修复了判断InjectFailed场景的错误 ([c97f092](https://github.com/kaokei/di/commit/c97f092744e178236b1317aab108f92d337eb943))
17
+
18
+ ### 1.0.22 (2021-10-07)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * **bugfix:** 修复dispose的bug ([eb5116d](https://github.com/kaokei/di/commit/eb5116d28139ad7c21738e089ce764e76609b3c6))
24
+
25
+ ### [1.0.21](https://github.com/kaokei/di/compare/v1.0.20...v1.0.21) (2021-09-16)
26
+
27
+
28
+ ### Features
29
+
30
+ * **inject:** 修改Inject的参数是必填项 ([2ec3dbe](https://github.com/kaokei/di/commit/2ec3dbeea8dc02ab0d8b43ce104192626cb8a9dd))
31
+
32
+ ### [1.0.20](https://github.com/kaokei/di/compare/v1.0.19...v1.0.20) (2021-08-22)
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * **reflect-metadata:** import reflect-metadata ([5e21184](https://github.com/kaokei/di/commit/5e21184f922f32d97640b42c96982313dc5c9ea4))
38
+
39
+ ### [1.0.19](https://github.com/kaokei/di/compare/v1.0.18...v1.0.19) (2021-08-22)
40
+
41
+
42
+ ### Bug Fixes
43
+
44
+ * **fix export:** 重新导出autobind ([ea721c2](https://github.com/kaokei/di/commit/ea721c28be8c0734e43b95a01bc234843346ca5e))
45
+
46
+ ### [1.0.18](https://github.com/kaokei/di/compare/v1.0.17...v1.0.18) (2021-08-21)
47
+
48
+ ### [1.0.17](https://github.com/kaokei/di/compare/v1.0.16...v1.0.17) (2021-08-21)
49
+
50
+
51
+ ### Bug Fixes
52
+
53
+ * **autobind:** export autobind ([4f2f4c8](https://github.com/kaokei/di/commit/4f2f4c83bbdb0bcb87bc44df608bdb6fc4858ec2))
54
+
55
+ ### [1.0.16](https://github.com/kaokei/di/compare/v1.0.15...v1.0.16) (2021-08-21)
56
+
57
+ ### [1.0.15](https://github.com/kaokei/di/compare/v1.0.14...v1.0.15) (2021-08-21)
58
+
59
+
60
+ ### Features
61
+
62
+ * **autobind:** add autobind-decorator pacakge ([ff60ead](https://github.com/kaokei/di/commit/ff60ead4eb892a15249d8ef74153451c16e0c696))
63
+
64
+ ### [1.0.14](https://github.com/kaokei/di/compare/v1.0.13...v1.0.14) (2021-08-06)
65
+
66
+
67
+ ### Features
68
+
69
+ * **util:** export utils ([458d75e](https://github.com/kaokei/di/commit/458d75e7583d4ca6bfa3c32755daf9b1e1f17b1a))
70
+
71
+ ### [1.0.13](https://github.com/kaokei/di/compare/v1.0.12...v1.0.13) (2021-08-06)
72
+
73
+
74
+ ### Features
75
+
76
+ * **merge:** 支持mergeHook ([427a1e2](https://github.com/kaokei/di/commit/427a1e2f9681284e579a96a94dce0f4ee96f0414))
77
+
78
+ ### [1.0.12](https://github.com/kaokei/di/compare/v1.0.10...v1.0.12) (2021-08-04)
79
+
80
+
81
+ ### Features
82
+
83
+ * **injector:** injector support dispose ([7b1246d](https://github.com/kaokei/di/commit/7b1246d31ad0a621fe7ee6e0b007d621fb28643b))
84
+
85
+ ### [1.0.10](https://github.com/kaokei/di/compare/v1.0.9...v1.0.10) (2021-08-03)
86
+
87
+ ### [1.0.9](https://github.com/kaokei/di/compare/v1.0.8...v1.0.9) (2021-07-01)
88
+
89
+ ### [1.0.8](https://github.com/kaokei/di/compare/v1.0.7...v1.0.8) (2021-06-29)
90
+
91
+
92
+ ### Bug Fixes
93
+
94
+ * **package.json:** set reflect-metadata to be peer dependency ([4368411](https://github.com/kaokei/di/commit/4368411ce44d0f0f754c8bf8e3f263e3f27dbed2))
95
+
96
+ ### [1.0.7](https://github.com/kaokei/di/compare/v1.0.6...v1.0.7) (2021-06-29)
97
+
98
+ ### [1.0.6](https://github.com/kaokei/di/compare/v1.0.5...v1.0.6) (2021-06-29)
99
+
100
+
101
+ ### Bug Fixes
102
+
103
+ * **index:** change location of reflect-metadata ([b7b8e03](https://github.com/kaokei/di/commit/b7b8e033554a3ea4604d3753947be5762e4b9032))
104
+
105
+ ### [1.0.5](https://github.com/kaokei/di/compare/v1.0.4...v1.0.5) (2021-06-29)
106
+
107
+
108
+ ### Bug Fixes
109
+
110
+ * **injector:** should return postHook service ([6c73a3e](https://github.com/kaokei/di/commit/6c73a3eb43a6d1670d446fcaaadcd1178ab51fda))
111
+
112
+ ### [1.0.4](https://github.com/kaokei/di/compare/v1.0.3...v1.0.4) (2021-06-29)
113
+
114
+
115
+ ### Features
116
+
117
+ * **injector:** add postHook ([db75b02](https://github.com/kaokei/di/commit/db75b02e049017ed959a83e310b3cb96e9514060))
118
+
119
+ ### [1.0.3](https://github.com/kaokei/di/compare/v1.0.1...v1.0.3) (2021-06-29)
120
+
121
+
122
+ ### Bug Fixes
123
+
124
+ * **ci:** modify ci name ([b43f69c](https://github.com/kaokei/di/commit/b43f69cbdfe2069f559045a95efc92a956b04d20))
package/README.md CHANGED
@@ -5,110 +5,15 @@
5
5
 
6
6
  </div>
7
7
 
8
- ## 待修改的 5 个名字
8
+ ## 文档
9
9
 
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)
10
+ [Document](https://www.kaokei.com/project/di/)
19
11
 
20
12
  ## 解决了什么问题?
21
13
 
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
- 考虑这样的场景,就是循环依赖了。小明要看书,请求小王帮忙读书,小王说读书可以是可以,但是我一直坐在椅子上,没有力气读书,你背我走一走吧,小明说你先帮我读书,我再被你走路,小王说你先背我走路,我再帮你读书。
63
-
64
- 像这种同一时刻,两种资源同时互相依赖即可称为循环依赖。
14
+ 基于 typescript 实现依赖注入能力。类似的目前比较流行的 library 是`InversifyJS`。
65
15
 
66
- 再回归到 es6 中,在 es6 的模块定义的时候,一般“较少”有循环依赖的场景。但是互相依赖的场景则是非常常见的。
67
-
68
- 比如调用 A 模块中的 a 方法时,会调用 B 模块中的 b 方法。就算 b 方法再次调用 a 方法,只要这种循环调用会中止即可,这也只是互相依赖,而不是循环依赖。
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
16
+ 其他类似的 library 可以[参考这里](https://github.com/topics/ioc?l=typescript)
112
17
 
113
18
  ### 已经支持的特性
114
19
 
@@ -121,11 +26,24 @@ npm run release patch 发布新版本
121
26
  - 支持属性注入
122
27
  - 支持部分循环依赖,对于不支持的循环依赖会有相应的提示
123
28
  - 支持类型提示,以及 InjectionKey 的类型提示
29
+ - 支持@Optional 以及初始值作为默认值
124
30
 
125
31
  ### 不支持的特性
126
32
 
127
33
  - 不支持 multi-injection
128
- - 不支持不能自己 new 的注入
129
- - 对于继承没有过多的支持
130
- - 没有 InversifyJS 中复杂的 binding 的 API,尽量采用`new Injector([providers])`
34
+ - 不支持不能自己 new 的注入,比如 react 类组件的实例化过程我们干预不了,因为 Injector 容器内部非常重要的一个工作就是 new 一个对象。
35
+ - 对于类的继承没有过多的支持,[参考这里](https://docs.typestack.community/typedi/v/develop/02-basic-usage-guide/07-inheritance)
36
+ - 没有 InversifyJS 中复杂的 binding 的 API,尽量采用`new Injector([providers])`,也就是一次性声明所有的`providers`
131
37
  - 暂时不实现 providers 中使用 forwardRef,主要是不了解使用场景,目前只支持在@Inject 中使用 forwardRef
38
+ - 不支持异步实例化,即该实例对象的状态和数据依赖服务器端数据,需要异步获取,等待获取数据成功之后才实例化对象。对于这种场景建议在实例对象中维护类似 loading/ready/inited 这种字段来表明数据是否准备完毕。
39
+ - 不支持 LazyInject
40
+ - 原来是导出了 autobind,后续删除了该导出,有业务需要可以自己 npm install 即可
41
+ - 不支持中间件,后续可以考虑完善中间件
42
+ - 不支持自定义装饰器,比如@Prev、@Post 等装饰器,类似 autobind,应该独立维护
43
+ - 不支持 onInit 生命周期钩子,虽然 Spring 中时支持的,但是实际场景中并不常用,[参考这里](https://github.com/angular/angular/issues/23235)
44
+
45
+ ### todo
46
+
47
+ 多次 Injectable 不需要报错
48
+
49
+ https://github.com/topics/dependency-injection?l=typescript