Skip to content

Commit 0858f83

Browse files
committed
feat: 删除 ProviderKey, 新增injectService
1 parent d1436dd commit 0858f83

File tree

10 files changed

+893
-1155
lines changed

10 files changed

+893
-1155
lines changed

docs/guide/api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ class Foo extends VueComponent {
107107

108108
在外部服务中获取当前的最近一级的注射器
109109

110+
## createCurrentInjector
111+
112+
在当前组件手动创建注射器
113+
114+
## injectService
115+
116+
手动注入服务,存在注射器或父级注射器
117+
110118
## useForwardRef
111119

112120
在HOC组件中使用这个方法可以转发真正的ref

example/module/basic/hello-world/hello-world.view.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { Mut, VueComponent } from 'vue3-oop'
1+
import { injectService, Mut, VueComponent } from 'vue3-oop'
22
import { Button, Card, Input } from 'ant-design-vue'
3+
import { withModifiers } from 'vue'
4+
import { RouterService } from '../../../router/router.service'
35

46
export class Base extends VueComponent {
57
@Mut() count = 1
@@ -10,7 +12,11 @@ export class Base extends VueComponent {
1012

1113
export class Child1 extends Base {
1214
render() {
13-
return <div onClick={() => this.count++}>{super.render()}</div>
15+
return (
16+
<div onClick={withModifiers(() => this.count++, ['once'])}>
17+
{super.render()}
18+
</div>
19+
)
1420
}
1521
}
1622

@@ -26,15 +32,16 @@ export class Child2 extends Child1 {
2632
}
2733

2834
export default class HelloWorldView extends VueComponent {
29-
static async = true
30-
3135
@Mut() count = 1
3236

3337
async init() {
3438
await new Promise((r) => setTimeout(r, 5000))
3539
}
3640

41+
router = injectService(RouterService)!
42+
3743
render() {
44+
console.log(this.router)
3845
return (
3946
<Card title={'加减功能'}>
4047
<Button type={'primary'} onClick={() => this.count++}>

example/router/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import type { RouteRecordRaw } from 'vue-router'
44
const moduleRoutes = import.meta.globEager('../module/**/*.router.ts')
55

66
export const routes: RouteRecordRaw[] = Reflect.ownKeys(moduleRoutes)
7-
.map((k) => moduleRoutes[k as string].default as RouteRecordRaw)
7+
.map((k) => (moduleRoutes[k as string] as any).default as RouteRecordRaw)
88
.filter(Boolean)

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,40 @@
5353
"@commitlint/cli": "^17.0.3",
5454
"@commitlint/config-conventional": "^17.0.3",
5555
"@nexhome/yorkie": "^2.0.8",
56-
"@release-it/conventional-changelog": "^5.0.0",
56+
"@release-it/conventional-changelog": "^5.1.0",
5757
"@types/lodash-es": "^4.17.6",
5858
"@types/markdown-it": "^12.2.3",
59-
"@types/node": "^18.0.4",
60-
"@types/prettier": "^2.6.3",
61-
"@typescript-eslint/eslint-plugin": "^5.30.6",
62-
"@typescript-eslint/parser": "^5.30.6",
63-
"@vitejs/plugin-vue": "^3.0.0",
64-
"@vitest/ui": "^0.18.0",
59+
"@types/node": "^18.7.6",
60+
"@types/prettier": "^2.7.0",
61+
"@typescript-eslint/eslint-plugin": "^5.33.1",
62+
"@typescript-eslint/parser": "^5.33.1",
63+
"@vitejs/plugin-vue": "^3.0.3",
64+
"@vitest/ui": "^0.22.0",
6565
"@vue/test-utils": "2.0.2",
66-
"@vue3-oop/plugin-vue-jsx": "^1.4.0",
67-
"ant-design-vue": "^3.2.10",
66+
"@vue3-oop/plugin-vue-jsx": "^1.4.1",
67+
"ant-design-vue": "^3.2.11",
6868
"autobind-decorator": "^2.4.0",
69-
"c8": "^7.11.3",
70-
"eslint": "^8.19.0",
69+
"c8": "^7.12.0",
70+
"eslint": "^8.22.0",
7171
"eslint-config-prettier": "^8.5.0",
7272
"eslint-plugin-prettier": "^4.2.1",
73-
"happy-dom": "^6.0.3",
73+
"happy-dom": "^6.0.4",
7474
"injection-js": "^2.4.0",
7575
"lint-staged": "^13.0.3",
7676
"lodash-es": "^4.17.21",
7777
"prettier": "^2.7.1",
78-
"release-it": "^15.1.1",
78+
"release-it": "^15.3.0",
7979
"rimraf": "^3.0.2",
80-
"sass": "^1.53.0",
80+
"sass": "^1.54.4",
8181
"tslib": "^2.4.0",
8282
"typescript": "^4.7.4",
83-
"vite": "^3.0.0",
84-
"vite-plugin-dts": "^1.3.0",
83+
"vite": "^3.0.8",
84+
"vite-plugin-dts": "^1.4.1",
8585
"vite-tsconfig-paths": "^3.5.0",
86-
"vitepress": "1.0.0-alpha.4",
87-
"vitest": "^0.18.0",
86+
"vitepress": "1.0.0-alpha.8",
87+
"vitest": "^0.22.0",
8888
"vue": "^3.2.37",
89-
"vue-router": "^4.1.2"
89+
"vue-router": "^4.1.3"
9090
},
9191
"commitlint": {
9292
"extends": [

0 commit comments

Comments
 (0)