Skip to content

Commit f13d1ef

Browse files
committed
feat: Ref重命名Mut
1 parent 6b46636 commit f13d1ef

File tree

14 files changed

+35
-35
lines changed

14 files changed

+35
-35
lines changed

docs/guide/api.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
# 装饰器
1414

15-
## Track
15+
## Mut
1616
- Type: 属性装饰器
1717

1818
声明变量为响应式
1919

2020
```tsx
2121
class Foo extends VueComponent {
22-
@Track() count = 1
22+
@Mut() count = 1
2323
}
2424
```
2525

@@ -30,7 +30,7 @@ class Foo extends VueComponent {
3030

3131
```tsx
3232
class Foo extends VueComponent {
33-
@Track() count = 1
33+
@Mut() count = 1
3434

3535
@Computed()
3636
get doubleCount() {

docs/guide/component.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ class Foo extends VueComponent {
7171

7272
## 响应式变量
7373

74-
响应式变量使用装饰器注解一下,主要有2个 `Track``Computed`,此时忘记 `.value` 的事情,
74+
响应式变量使用装饰器注解一下,主要有2个 `Mut``Computed`,此时忘记 `.value` 的事情,
7575
就是正常普通的变量定义,加上装饰器就是告诉框架当此变量变化的时候我要刷新视图
7676

7777
```tsx
7878
class Foo extends VueComponent {
79-
@Track() count = 1
79+
@Mut() count = 1
8080

8181
@Computed()
8282
get doubleCount() {
@@ -123,7 +123,7 @@ class Foo extends VueComponent {
123123
watch(() => this.count, (n, o) => console.log('change', n, o))
124124
}
125125

126-
@Track() count = 1
126+
@Mut() count = 1
127127

128128
render() {
129129
return <span onClick={() => this.count++}>{this.count}</span>

docs/guide/di.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Injectable } from 'injection-js'
1616
// 定义服务 加上此装饰器表明我有需要其他服务,如果不需要,可以不加
1717
@Injectable()
1818
class CountService extends VueService {
19-
@Track() count = 1
19+
@Mut() count = 1
2020

2121
add() {
2222
this.count++
@@ -46,7 +46,7 @@ import { VueComponent } from './component'
4646
import { SkipSelf } from 'injection-js'
4747

4848
class CountService extends VueService {
49-
@Track() count = 1
49+
@Mut() count = 1
5050

5151
add() {
5252
this.count++

docs/guide/service.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class PositionService extends VueService {
3838
onBeforeUnmount(() => window.removeEventListener('mousemove', this.change))
3939
}
4040

41-
@Track() x = 0
42-
@Track() y = 0
41+
@Mut() x = 0
42+
@Mut() y = 0
4343

4444
@Autobind()
4545
private change(e: MouseEvent) {

docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Foo extends VueComponent<Foo_Props> {
3939
}
4040

4141
// 组件自身状态
42-
@Track() count = 1
42+
@Mut() count = 1
4343

4444
// 计算属性
4545
@Computed()

example/count.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Autobind, Track, VueService } from '@/index'
1+
import { Autobind, Mut, VueService } from '@/index'
22

33
export class CountService extends VueService {
4-
@Track() count = 1
4+
@Mut() count = 1
55

66
@Autobind()
77
add() {

example/example.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Autobind, Track, VueComponent, VueService } from 'vue3-oop'
1+
import { Autobind, Mut, VueComponent, VueService } from 'vue3-oop'
22
import { onBeforeUnmount } from 'vue'
33

44
class PositionService extends VueService {
@@ -8,8 +8,8 @@ class PositionService extends VueService {
88
onBeforeUnmount(() => window.removeEventListener('mousemove', this.change))
99
}
1010

11-
@Track() x = 0
12-
@Track() y = 0
11+
@Mut() x = 0
12+
@Mut() y = 0
1313

1414
@Autobind()
1515
private change(e: MouseEvent) {

example/module/auth/login.view.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, VueComponent } from '@/index'
22
import { UserService } from './user.service'
33
import { Button, Col, Form, Input, Row } from 'ant-design-vue'
4-
import { Track } from '@/decorators/track'
4+
import { Mut } from '@/decorators/mut'
55
import { CatchLoading } from '../../common/decorators/catch.decorator'
66
import { Autobind } from '@/helper'
77
import { CountService } from '../../count.service'
@@ -19,8 +19,8 @@ export default class LoginView extends VueComponent {
1919
) {
2020
super()
2121
}
22-
@Track() loading = false
23-
@Track() model = {
22+
@Mut() loading = false
23+
@Mut() model = {
2424
name: '',
2525
pwd: '',
2626
}

example/module/auth/user.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Hook, Track, VueService } from '@/index'
1+
import { Hook, Mut, VueService } from '@/index'
22
import { Inject, Injectable } from 'injection-js'
33
import { RouterService } from '../../router/router.service'
44
import { AxiosInstance } from 'axios'
@@ -11,7 +11,7 @@ export class UserService extends VueService {
1111
this.guardHttp()
1212
this.guardRouter()
1313
}
14-
@Track() token = ''
14+
@Mut() token = ''
1515

1616
private _requestGuard: number
1717

example/size.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Hook, Track, VueService } from 'vue3-oop'
1+
import { Hook, Mut, VueService } from 'vue3-oop'
22
import { ref, watchEffect } from 'vue'
33
import { debounce } from 'lodash-es'
44

@@ -21,8 +21,8 @@ export class SizeService extends VueService {
2121
this.debounceSet(entry.target.clientWidth, entry.target.clientHeight)
2222
}
2323
})
24-
@Track() x = 0
25-
@Track() y = 0
24+
@Mut() x = 0
25+
@Mut() y = 0
2626

2727
debounceSet = debounce((x: number, y: number) => {
2828
this.x = x

src/decorators/track.ts renamed to src/decorators/mut.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { ref } from 'vue'
22
import { Hanlder } from '../type'
33
import { getProtoMetadata } from '../helper'
44

5-
const MetadataKey = Symbol('Track')
5+
const MetadataKey = Symbol('Mut')
66

7-
export function Track(): PropertyDecorator {
7+
export function Mut(): PropertyDecorator {
88
return function (target: any, key: string | symbol) {
99
let list: (string | symbol)[] = Reflect.getMetadata(MetadataKey, target) || []
1010
list = list.slice()
@@ -32,14 +32,14 @@ function handler(targetThis: Record<any, any>) {
3232
}
3333
}
3434

35-
export const TrackHandler: Hanlder = {
36-
key: 'Track',
35+
export const MutHandler: Hanlder = {
36+
key: 'Mut',
3737
handler,
3838
}
3939

4040
/**
41-
* @deprecated 因与vue的ref冲突,故改名为 Track
41+
* @deprecated 因与vue的ref冲突,故改名为 Mut
4242
*/
4343
export function Ref() {
44-
return Track()
44+
return Mut()
4545
}

src/extends/component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ComponentPublicInstance, getCurrentInstance, InjectionKey, provide, VNodeChild, VNodeProps } from 'vue'
22
import { getEmitsFromProps, useCtx, useProps } from '../helper'
33
import { Hanlder, VueComponentStaticContructor, WithSlotTypes, WithVModel, WithVSlots } from '../type'
4-
import { TrackHandler } from '../decorators/track'
4+
import { MutHandler } from '../decorators/mut'
55
import { ComputedHandler } from '../decorators/computed'
66
import { HookHandler } from '../decorators/hook'
77
import { LinkHandler } from '../decorators/link'
@@ -19,7 +19,7 @@ export abstract class VueComponent<T extends {} = {}> {
1919
/** 热更新使用 */
2020
static __hmrId?: string
2121
/** 装饰器处理 */
22-
static handler: Hanlder[] = [TrackHandler, ComputedHandler, LinkHandler, HookHandler]
22+
static handler: Hanlder[] = [MutHandler, ComputedHandler, LinkHandler, HookHandler]
2323
/** 是否自定义解析组件 */
2424
static resolveComponent = resolveComponent
2525
static __vccOpts__value?: any

src/extends/service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TrackHandler } from '../decorators/track'
1+
import { MutHandler } from '../decorators/mut'
22
import { ComputedHandler } from '../decorators/computed'
33
import { HookHandler } from '../decorators/hook'
44
import { provide } from 'vue'
@@ -8,7 +8,7 @@ import { LinkHandler } from '../decorators/link'
88
export const ProviderKey = 'ProviderKey' as const
99

1010
export abstract class VueService {
11-
static handler: Hanlder[] = [TrackHandler, ComputedHandler, LinkHandler, HookHandler]
11+
static handler: Hanlder[] = [MutHandler, ComputedHandler, LinkHandler, HookHandler]
1212
public constructor() {
1313
const ThisConstructor = this.constructor as VueComponentStaticContructor
1414
if (ThisConstructor.ProviderKey) provide(ThisConstructor.ProviderKey, this)

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { VueComponent, GlobalStoreKey } from './extends/component'
22
export { VueService, ProviderKey } from './extends/service'
3-
export { Ref, Track } from './decorators/track'
3+
export { Ref, Mut } from './decorators/mut'
44
export { Computed } from './decorators/computed'
55
export { Link } from './decorators/link'
66
export { Hook } from './decorators/hook'

0 commit comments

Comments
 (0)