@kaokei/di 1.1.0 → 2.0.1

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 (51) hide show
  1. package/README.md +29 -4
  2. package/dist/index.cjs.js +358 -403
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.cjs.min.js +2 -2
  5. package/dist/index.cjs.min.js.map +1 -1
  6. package/dist/index.cjs.runtime.js +346 -384
  7. package/dist/index.cjs.runtime.js.map +1 -1
  8. package/dist/index.cjs.runtime.min.js +2 -2
  9. package/dist/index.cjs.runtime.min.js.map +1 -1
  10. package/dist/index.esm.js +356 -401
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +3 -3
  13. package/dist/index.esm.min.js.map +1 -1
  14. package/dist/index.esm.runtime.js +344 -373
  15. package/dist/index.esm.runtime.js.map +1 -1
  16. package/dist/index.esm.runtime.min.js +3 -3
  17. package/dist/index.esm.runtime.min.js.map +1 -1
  18. package/dist/index.iife.js +358 -403
  19. package/dist/index.iife.js.map +1 -1
  20. package/dist/index.iife.min.js +3 -3
  21. package/dist/index.iife.min.js.map +1 -1
  22. package/dist/src/Injector.d.ts +142 -131
  23. package/dist/src/Injector.d.ts.map +1 -1
  24. package/dist/src/constants.d.ts +16 -17
  25. package/dist/src/constants.d.ts.map +1 -1
  26. package/dist/src/decorator.d.ts +41 -41
  27. package/dist/src/decorator.d.ts.map +1 -1
  28. package/dist/src/errors/CircularDependencyError.d.ts +5 -5
  29. package/dist/src/errors/CircularDependencyError.d.ts.map +1 -1
  30. package/dist/src/errors/ConstructorInjectMissTokenError.d.ts +6 -0
  31. package/dist/src/errors/ConstructorInjectMissTokenError.d.ts.map +1 -0
  32. package/dist/src/errors/InjectFailedError.d.ts +5 -5
  33. package/dist/src/errors/InjectFailedError.d.ts.map +1 -1
  34. package/dist/src/errors/PropertyInjectMissTokenError.d.ts +6 -0
  35. package/dist/src/errors/PropertyInjectMissTokenError.d.ts.map +1 -0
  36. package/dist/src/errors/ProviderNotValidError.d.ts +5 -5
  37. package/dist/src/errors/ProviderNotValidError.d.ts.map +1 -1
  38. package/dist/src/errors/TokenNotFoundError.d.ts +5 -5
  39. package/dist/src/errors/TokenNotFoundError.d.ts.map +1 -1
  40. package/dist/src/errors/index.d.ts +6 -4
  41. package/dist/src/errors/index.d.ts.map +1 -1
  42. package/dist/src/forwardRef.d.ts +6 -6
  43. package/dist/src/forwardRef.d.ts.map +1 -1
  44. package/dist/src/index.d.ts +7 -7
  45. package/dist/src/index.d.ts.map +1 -1
  46. package/dist/src/utils.d.ts +3 -2
  47. package/dist/src/utils.d.ts.map +1 -1
  48. package/package.json +38 -37
  49. package/CHANGELOG.md +0 -135
  50. package/dist/src/types/index.d.ts +0 -2
  51. package/dist/src/types/index.d.ts.map +0 -1
package/README.md CHANGED
@@ -3,9 +3,20 @@
3
3
 
4
4
  [![Build Status](https://github.com/kaokei/di/actions/workflows/build.yml/badge.svg)](https://github.com/kaokei/di/actions/workflows/build.yml)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/kaokei/di/badge.svg?branch=main)](https://coveralls.io/github/kaokei/di?branch=main)
6
+ [![Downloads](https://img.shields.io/npm/dm/@kaokei/di.svg?sanitize=true)](https://npmcharts.com/compare/@kaokei/di?minimal=true)
7
+ [![Version](https://img.shields.io/npm/v/@kaokei/di.svg?sanitize=true)](https://www.npmjs.com/package/@kaokei/di)
8
+ [![License](https://img.shields.io/npm/l/@kaokei/di.svg?sanitize=true)](https://www.npmjs.com/package/@kaokei/di)
6
9
 
7
10
  </div>
8
11
 
12
+ - [documentation](https://kaokei.com/project/di/)
13
+ - [online playground](https://codesandbox.io/s/di-playground-zjnyv)
14
+ - [online demo](https://kaokei.com/project/di/)
15
+
16
+ ```bash
17
+ npm install @kaokei/di reflect-metadata
18
+ ```
19
+
9
20
  ## 灵感
10
21
 
11
22
  Inspired by [Spring](https://spring.io/), [Angular](https://angular.io/), [typedi](https://github.com/typestack/typedi), [InversifyJS](https://github.com/inversify/InversifyJS)
@@ -22,10 +33,6 @@ Inspired by [Spring](https://spring.io/), [Angular](https://angular.io/), [typed
22
33
 
23
34
  基于 typescript 实现依赖注入能力。类似的目前比较流行的 library 是`InversifyJS`和`typedi`。
24
35
 
25
- [详细文档地址](https://kaokei.com/project/di/)
26
-
27
- [online playground](https://codesandbox.io/s/di-playground-zjnyv)
28
-
29
36
  ## 已经支持的特性
30
37
 
31
38
  - 支持类,Symbol,字符串等作为服务的 token
@@ -52,3 +59,21 @@ Inspired by [Spring](https://spring.io/), [Angular](https://angular.io/), [typed
52
59
  - 不支持中间件,有需要可以[参考这里](https://github.com/inversify/InversifyJS/blob/master/wiki/middleware.md)
53
60
  - 原来确实导出了 autobind,后续删除了该导出,有业务需要可以自己 `npm install autobind-decorator` 即可。
54
61
  - 没有实现自定义装饰器,比如@Prev、@Post、@Aop 等装饰器,类似 autobind,应该独立维护。
62
+
63
+ ## 已知问题
64
+
65
+ 循环依赖导致的问题运行时报错。
66
+
67
+ - [Design:type metadata for cyclic dependencies throw at runtime #27519](https://github.com/microsoft/TypeScript/issues/27519)
68
+ - [Support for classes](https://github.com/inversify/InversifyJS/blob/master/wiki/classes_as_id.md#known-limitation-classes-as-identifiers-and-circular-dependencies)
69
+
70
+ 经过一番探究,有不同的场景会导致这个问题。
71
+
72
+ 问题一:A 类和 B 类循环依赖。
73
+
74
+ 解决方案:使用 forwardRef 解藕 A 和 B 的实例化过程。类似 InversifyJS 中的 lazyInject。
75
+
76
+ 问题二:已经使用 forawrdRef 解藕了 A 和 B。仍然有运行时错误。
77
+
78
+ 解决方案:这是因为 tsconfig.json 中的 target 不是 es5。通过测试发现只有设置为 es5 才能避免这个问题。
79
+ 可以[参考这个项目](https://github.com/kaokei/test-webpack-typescript)