Skip to content

Commit 455739a

Browse files
committed
feat: Ref重命名Track
BREAKING CHANGE: Ref因与vue的Ref重名,故改名为Track
1 parent 2593174 commit 455739a

File tree

18 files changed

+105
-35
lines changed

18 files changed

+105
-35
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ pnpm add vue3-oop
3636

3737
### vite配置
3838

39-
因为esbuild不支持装饰器的metadata属性,所以需要安装 [vite-plugin-ts](https://github.com/CarterLi/vite/tree/main/packages/plugin-vue-jsx#readme) 插件使用原始ts编译
39+
因为esbuild不支持装饰器的metadata属性,所以需要安装 [rollup-plugin-typescript2](https://github.com/ezolenko/rollup-plugin-typescript2) 插件使用原始ts编译
4040

4141
### 定义组件
4242

4343
```typescript jsx
44-
import { Autobind, ComponentProps, Computed, Hook, Link, Ref, VueComponent } from 'vue3-oop'
44+
import { Autobind, ComponentProps, Computed, Hook, Link, Track, VueComponent } from 'vue3-oop'
4545
import { Directive, VNodeChild, watch } from 'vue'
4646

4747
const focusDirective: Directive = {
@@ -78,7 +78,7 @@ class Foo extends VueComponent<Foo_Props> {
7878
}
7979

8080
// 组件自身状态
81-
@Ref() count = 1
81+
@Track() count = 1
8282

8383
// 计算属性
8484
@Computed()
@@ -127,7 +127,7 @@ class Foo extends VueComponent<Foo_Props> {
127127
128128
```typescript
129129
class CountService extends VueService {
130-
@Ref() count = 1
130+
@Track() count = 1
131131
add() {
132132
this.count++
133133
}

docs/guide/api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
# 装饰器
1414

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

1818
声明变量为响应式
1919

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

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

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

3535
@Computed()
3636
get doubleCount() {

docs/guide/component.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ class Foo extends VueComponent {
7171

7272
## 响应式变量
7373

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

7777
```tsx
7878
class Foo extends VueComponent {
79-
@Ref() count = 1
79+
@Track() 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-
@Ref() count = 1
126+
@Track() count = 1
127127

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

docs/guide/di.md

Lines changed: 2 additions & 2 deletions
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-
@Ref() count = 1
19+
@Track() 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-
@Ref() count = 1
49+
@Track() count = 1
5050

5151
add() {
5252
this.count++

docs/guide/service.md

Lines changed: 2 additions & 2 deletions
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-
@Ref() x = 0
42-
@Ref() y = 0
41+
@Track() x = 0
42+
@Track() y = 0
4343

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

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Foo extends VueComponent<Foo_Props> {
3939
}
4040

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

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

example/count.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Autobind, Ref, VueService } from '@/index'
1+
import { Autobind, Track, VueService } from '@/index'
22

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

66
@Autobind()
77
add() {

example/example.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Autobind, Ref, VueComponent, VueService } from 'vue3-oop'
1+
import { Autobind, Track, 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-
@Ref() x = 0
12-
@Ref() y = 0
11+
@Track() x = 0
12+
@Track() y = 0
1313

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

example/main.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { Component, VueComponent } from 'vue3-oop'
33
import { createApp } from 'vue'
44
import './theme/app.css'
55
import { CountService } from './count.service'
6+
import { SizeService } from './size.service'
67

78
@Component()
89
class Home extends VueComponent {
9-
constructor(private countService: CountService) {
10+
constructor(private countService: CountService, private sizeService: SizeService) {
1011
super()
1112
}
1213

@@ -16,6 +17,19 @@ class Home extends VueComponent {
1617
<h2>count: {this.countService.count}</h2>
1718
<button onClick={() => this.countService.add()}>+</button>
1819
<button onClick={() => this.countService.remove()}>-</button>
20+
<p>
21+
矩形大小: 宽度: {this.sizeService.x} 长度: {this.sizeService.y}
22+
</p>
23+
<div
24+
ref={this.sizeService.target}
25+
style={{
26+
width: '100px',
27+
height: '100px',
28+
resize: 'both',
29+
border: '1px solid #ccc',
30+
overflow: 'scroll',
31+
}}
32+
></div>
1933
</div>
2034
)
2135
}

example/module/auth/login.view.tsx

Lines changed: 3 additions & 3 deletions
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 { Ref } from '@/decorators/ref'
4+
import { Track } from '@/decorators/track'
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-
@Ref() loading = false
23-
@Ref() model = {
22+
@Track() loading = false
23+
@Track() model = {
2424
name: '',
2525
pwd: '',
2626
}

0 commit comments

Comments
 (0)