Skip to content

Commit 4cb5239

Browse files
committed
feat: Mut装饰器支持shallow, customRef
1 parent 0b02dd9 commit 4cb5239

25 files changed

+263
-553
lines changed

docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ features:
88
- title: 类组件
99
details: 功能与类型融为一体,无需多次声明类型,独立的属性类型声明,各种HOC组合轻而易举
1010
- title: 自动的依赖注入
11-
details: 基于动态解析的 injection-js 依赖注入,让使用服务丝般自然
11+
details: 基于动态解析的 injection-js 依赖注入,让使用服务丝般顺滑
1212
- title: vue3无ref编程
1313
details: 无需关注ref及其value,正常声明变量,编程体验更自然
1414
---

example/api/http.ts

-8
This file was deleted.

example/app.tsx

-41
This file was deleted.

example/common/decorators/catch.decorator.ts

-22
This file was deleted.

example/layout/default.layout.tsx

-8
This file was deleted.

example/main.tsx

+49-46
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,73 @@
11
import '@abraham/reflection'
2-
import { Component, Computed, Hook, Link, Mut, VueComponent } from 'vue3-oop'
3-
import { createApp, watchSyncEffect } from 'vue'
4-
import './theme/app.css'
5-
import { CountService } from './count.service'
6-
import { SizeService } from './size.service'
2+
import { Component, Computed, Hook, Mut, VueComponent, VueService } from 'vue3-oop'
3+
import { createApp } from 'vue'
74

8-
class Child extends VueComponent {
9-
render() {
10-
console.log('render')
11-
return (
12-
<div>
13-
111
14-
<div>{this.context.slots.default?.()}</div>
15-
</div>
16-
)
5+
const debounce = (delay: number) => {
6+
let timeout: number | undefined
7+
return (track: any, trigger: any) => {
8+
let value: any
9+
return {
10+
get() {
11+
track()
12+
return value
13+
},
14+
set(newValue: any) {
15+
clearTimeout(timeout)
16+
timeout = window.setTimeout(() => {
17+
value = newValue
18+
trigger()
19+
}, delay)
20+
},
21+
}
1722
}
1823
}
1924

20-
@Component()
25+
class CountService extends VueService {
26+
@Mut() count = 1
27+
}
28+
2129
class Home extends VueComponent {
22-
constructor(private countService: CountService, private sizeService: SizeService) {
23-
super()
24-
watchSyncEffect(() => this.count > 2)
25-
}
30+
@Mut(debounce(1000)) _count = ''
2631

27-
@Mut() count = 1
32+
@Mut() obj = { name: 123 }
2833

2934
@Computed()
3035
get double() {
31-
return this.count * 2
36+
return this._count
37+
}
38+
set double(val: string) {
39+
this._count = val.toUpperCase()
3240
}
33-
list = new Array(10).fill(1)
34-
35-
@Link() aaa: Child[]
3641

3742
@Hook('Mounted')
3843
mounted() {
39-
console.log(this.aaa)
44+
console.log('mounted')
45+
}
46+
47+
render() {
48+
console.log(this.obj)
49+
console.log('render')
50+
return <input type="text" v-model={this.double} />
4051
}
52+
}
4153

54+
@Component()
55+
class Home1 extends Home {
56+
constructor(private cs: CountService) {
57+
super()
58+
console.log(cs)
59+
}
60+
@Mut() count1 = 111
4261
render() {
4362
return (
44-
<div style={{ textAlign: 'center' }}>
45-
<Child>
46-
<div>11111</div>
47-
</Child>
48-
<h2>count: {this.countService.count}</h2>
49-
<button onClick={() => this.countService.add()}>+</button>
50-
<button onClick={() => this.countService.remove()}>-</button>
51-
<p>
52-
矩形大小: 宽度: {this.sizeService.x} 长度: {this.sizeService.y}
53-
</p>
54-
<div
55-
ref={this.sizeService.target}
56-
style={{
57-
width: '100px',
58-
height: '100px',
59-
resize: 'both',
60-
border: '1px solid #ccc',
61-
overflow: 'scroll',
62-
}}
63-
></div>
63+
<div>
64+
<h5 onClick={() => this.cs.count++}>{this.cs.count}</h5>
65+
<h2 onClick={() => this.count1++}>1111{this.count1}</h2>
66+
{super.render()}
6467
</div>
6568
)
6669
}
6770
}
6871

69-
const app = createApp(Home)
72+
const app = createApp(Home1)
7073
app.mount('#app')

example/module/auth/login.view.tsx

-95
This file was deleted.

example/module/auth/user.service.ts

-40
This file was deleted.

example/module/home/home.view.tsx

-49
This file was deleted.

0 commit comments

Comments
 (0)