@kaokei/di 1.0.25 → 1.1.0

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 CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
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
4
 
5
+ ## [1.1.0](https://github.com/kaokei/di/compare/v1.0.25...v1.1.0) (2022-02-11)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **typo:** 修复文字错误 ([2fdb91f](https://github.com/kaokei/di/commit/2fdb91ff95eab8c1c13153e5c267ce584bcf985b))
11
+
5
12
  ### [1.0.25](https://github.com/kaokei/di/compare/v1.0.24...v1.0.25) (2021-12-11)
6
13
 
7
14
  ### [1.0.24](https://github.com/kaokei/di/compare/v1.0.23...v1.0.24) (2021-12-11)
package/README.md CHANGED
@@ -6,43 +6,49 @@
6
6
 
7
7
  </div>
8
8
 
9
- ## 文档
9
+ ## 灵感
10
10
 
11
- [Document](https://www.kaokei.com/project/di/)
11
+ Inspired by [Spring](https://spring.io/), [Angular](https://angular.io/), [typedi](https://github.com/typestack/typedi), [InversifyJS](https://github.com/inversify/InversifyJS)
12
12
 
13
- ## 解决了什么问题?
13
+ 其他类似的 library 可以[参考这里](https://github.com/topics/ioc?l=typescript)和[参考这里](https://github.com/topics/dependency-injection?l=typescript)
14
14
 
15
- 基于 typescript 实现依赖注入能力。类似的目前比较流行的 library 是`InversifyJS`。
15
+ 最初接触依赖注入是从 Spring 中开始的,依稀记得我的第一份工作是 java 开发,在第一次开发业务需求的时候,还只知道`new`一个类来获取对象。然后我就在代码中 new 了很多实例对象。不出意外的出现问题了,组长就开始帮我调试代码,最终组长告诉我不要自己手动`new`实例对象,只需要在`XML`文件中配置对应的 bean 对象即可。这给当时的我留下了深刻的印象。现在回想起来,如果我是当时的组长,我肯定会非常生气,连这么基础的东西都不知道。
16
16
 
17
- 其他类似的 library 可以[参考这里](https://github.com/topics/ioc?l=typescript)[参考这里](https://github.com/topics/dependency-injection?l=typescript)
17
+ 后来又接触到 Angular,第一次了解到依赖注入在前端的应用。最关键的是我之前有使用过 vue react,先入为主的认为 Angular 中一定也有一个全局的 store,但是却怎么也找不到这个 store 对象,反而都是碎片化的 service。后来才反应过来,多 service 其实可以理解为多 store,如果整个项目只有一个 service,那么不就退化成和 vue 以及 react 一样了吗?只不过 service 在 Angular 中非常方便使用而且易于控制作用范围,相对的 vue 中的 store 的 module 本质还是全局范围可见的不同命名空间而已。
18
+
19
+ 所以我的想法就是要把 angular 的 service 特性迁移到 vue 和 react 中。本库作为一个基础库,被[user-vue-service](https://github.com/kaokei/use-vue-service)等库依赖。
20
+
21
+ ## 解决了什么问题?
22
+
23
+ 基于 typescript 实现依赖注入能力。类似的目前比较流行的 library 是`InversifyJS`和`typedi`。
18
24
 
19
- ### playground
25
+ [详细文档地址](https://kaokei.com/project/di/)
20
26
 
21
- https://codesandbox.io/s/di-playground-zjnyv
27
+ [online playground](https://codesandbox.io/s/di-playground-zjnyv)
22
28
 
23
- ### 已经支持的特性
29
+ ## 已经支持的特性
24
30
 
25
31
  - 支持类,Symbol,字符串等作为服务的 token
26
32
  - 支持类,值,工厂函数等作为服务
27
33
  - 支持@Inject、@Skip、@Self、@Optional 以及 forwardRef 控制获取服务
28
34
  - 支持@Optional 配置可选注入以及类属性的初始值作为默认值
29
35
  - Injector 作为 DI 容器,易于测试
30
- - 同一个服务在同一个 Injector 中一定是单例的
36
+ - 同一个服务在同一个 Injector 中一定是单例的。相对的[Inversify 支持 3 种 Scope](https://github.com/inversify/InversifyJS/blob/master/wiki/scope.md)。
31
37
  - 支持分层 DI 系统
32
38
  - 支持属性注入和构造函数注入
33
39
  - 支持部分循环依赖,对于不支持的循环依赖会有相应的提示
34
40
  - 支持类型提示,以及 InjectionKey 的类型提示
35
41
  - 支持 dispose 生命周期钩子
36
42
 
37
- ### 不支持的特性
43
+ ## 不支持的特性
38
44
 
39
- - 不支持 multi-injection
40
- - 不支持不能自己 new 的注入,比如 react 类组件的实例化过程我们干预不了,因为 Injector 容器内部非常重要的一个工作就是 new 一个对象。
45
+ - 不支持 multi-injection,有需要可以[参考这里](https://github.com/inversify/InversifyJS/blob/master/wiki/multi_injection.md)
46
+ - 不支持不能自己 new 的注入,比如 react 类组件的实例化过程我们干预不了,所以不能在 react 类组件上使用依赖注入。有需要可以[参考这里](https://itnext.io/dependency-injection-in-react-using-inversifyjs-a38ff0c6601)
41
47
  - 对于类的继承没有过多的支持,[参考这里](https://docs.typestack.community/typedi/v/develop/02-basic-usage-guide/07-inheritance)以及[参考这里](https://github.com/inversify/InversifyJS/blob/master/wiki/inheritance.md)
42
48
  - 暂时不实现 providers 中使用 forwardRef,主要是不了解使用场景,目前只支持在@Inject 中使用 forwardRef
43
49
  - 不支持异步实例化,即该实例对象的状态和数据依赖服务器端数据,需要异步获取,等待获取数据成功之后才实例化对象。对于这种场景建议在实例对象中维护类似 loading/ready/inited 这种字段来表明数据是否准备完毕。
44
50
  - 不支持 LazyInject
45
- - 不支持 onInit 生命周期钩子,虽然 Spring 中时支持的,但是实际场景中并不常用,[参考这里](https://github.com/angular/angular/issues/23235)
46
- - 不支持自定义装饰器,比如@Prev、@Post 等装饰器,类似 autobind,应该独立维护
47
- - 原来确实导出了 autobind,后续删除了该导出,有业务需要可以自己 `npm install autobind-decorator` 即可
48
- - 不支持中间件
51
+ - 不支持 onInit/PostConstruct 生命周期钩子,虽然 Spring 中是支持的,但是实际场景中并不常用,[参考这里](https://github.com/angular/angular/issues/23235)以及[参考这里](https://github.com/inversify/InversifyJS/blob/master/wiki/post_construct.md)
52
+ - 不支持中间件,有需要可以[参考这里](https://github.com/inversify/InversifyJS/blob/master/wiki/middleware.md)
53
+ - 原来确实导出了 autobind,后续删除了该导出,有业务需要可以自己 `npm install autobind-decorator` 即可。
54
+ - 没有实现自定义装饰器,比如@Prev、@Post、@Aop 等装饰器,类似 autobind,应该独立维护。
package/dist/index.cjs.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @kaokei/di
3
3
  * Tiny di library depend on typescript and reflect-metadata
4
4
  *
5
- * @version 1.0.25
5
+ * @version 1.1.0
6
6
  * @author kaokei
7
7
  * @license MIT
8
8
  * @link https://github.com/kaokei/di
@@ -2,7 +2,7 @@
2
2
  * @kaokei/di
3
3
  * Tiny di library depend on typescript and reflect-metadata
4
4
  *
5
- * @version 1.0.25
5
+ * @version 1.1.0
6
6
  * @author kaokei
7
7
  * @license MIT
8
8
  * @link https://github.com/kaokei/di
@@ -2,7 +2,7 @@
2
2
  * @kaokei/di
3
3
  * Tiny di library depend on typescript and reflect-metadata
4
4
  *
5
- * @version 1.0.25
5
+ * @version 1.1.0
6
6
  * @author kaokei
7
7
  * @license MIT
8
8
  * @link https://github.com/kaokei/di
@@ -2,7 +2,7 @@
2
2
  * @kaokei/di
3
3
  * Tiny di library depend on typescript and reflect-metadata
4
4
  *
5
- * @version 1.0.25
5
+ * @version 1.1.0
6
6
  * @author kaokei
7
7
  * @license MIT
8
8
  * @link https://github.com/kaokei/di
package/dist/index.esm.js CHANGED
@@ -48,7 +48,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
48
48
  * @kaokei/di
49
49
  * Tiny di library depend on typescript and reflect-metadata
50
50
  *
51
- * @version 1.0.25
51
+ * @version 1.1.0
52
52
  * @author kaokei
53
53
  * @license MIT
54
54
  * @link https://github.com/kaokei/di
@@ -3,7 +3,7 @@ function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterat
3
3
  * @kaokei/di
4
4
  * Tiny di library depend on typescript and reflect-metadata
5
5
  *
6
- * @version 1.0.25
6
+ * @version 1.1.0
7
7
  * @author kaokei
8
8
  * @license MIT
9
9
  * @link https://github.com/kaokei/di
@@ -21,7 +21,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
21
21
  * @kaokei/di
22
22
  * Tiny di library depend on typescript and reflect-metadata
23
23
  *
24
- * @version 1.0.25
24
+ * @version 1.1.0
25
25
  * @author kaokei
26
26
  * @license MIT
27
27
  * @link https://github.com/kaokei/di
@@ -3,7 +3,7 @@ import e from"@babel/runtime/helpers/esm/construct";import t from"@babel/runtime
3
3
  * @kaokei/di
4
4
  * Tiny di library depend on typescript and reflect-metadata
5
5
  *
6
- * @version 1.0.25
6
+ * @version 1.1.0
7
7
  * @author kaokei
8
8
  * @license MIT
9
9
  * @link https://github.com/kaokei/di
@@ -48,7 +48,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
48
48
  * @kaokei/di
49
49
  * Tiny di library depend on typescript and reflect-metadata
50
50
  *
51
- * @version 1.0.25
51
+ * @version 1.1.0
52
52
  * @author kaokei
53
53
  * @license MIT
54
54
  * @link https://github.com/kaokei/di
@@ -3,7 +3,7 @@ function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof S
3
3
  * @kaokei/di
4
4
  * Tiny di library depend on typescript and reflect-metadata
5
5
  *
6
- * @version 1.0.25
6
+ * @version 1.1.0
7
7
  * @author kaokei
8
8
  * @license MIT
9
9
  * @link https://github.com/kaokei/di
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaokei/di",
3
- "version": "1.0.25",
3
+ "version": "1.1.0",
4
4
  "description": "Tiny di library depend on typescript and reflect-metadata",
5
5
  "main": "./dist/index.cjs.runtime.min.js",
6
6
  "module": "./dist/index.esm.runtime.min.js",