Skip to content

Commit

Permalink
feat: Mut装饰器支持shallow, customRef
Browse files Browse the repository at this point in the history
  • Loading branch information
agileago committed Jan 16, 2022
1 parent 0b02dd9 commit 4cb5239
Show file tree
Hide file tree
Showing 25 changed files with 263 additions and 553 deletions.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ features:
- title: 类组件
details: 功能与类型融为一体,无需多次声明类型,独立的属性类型声明,各种HOC组合轻而易举
- title: 自动的依赖注入
details: 基于动态解析的 injection-js 依赖注入,让使用服务丝般自然
details: 基于动态解析的 injection-js 依赖注入,让使用服务丝般顺滑
- title: vue3无ref编程
details: 无需关注ref及其value,正常声明变量,编程体验更自然
---
Expand Down
8 changes: 0 additions & 8 deletions example/api/http.ts

This file was deleted.

41 changes: 0 additions & 41 deletions example/app.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions example/common/decorators/catch.decorator.ts

This file was deleted.

8 changes: 0 additions & 8 deletions example/layout/default.layout.tsx

This file was deleted.

95 changes: 49 additions & 46 deletions example/main.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,73 @@
import '@abraham/reflection'
import { Component, Computed, Hook, Link, Mut, VueComponent } from 'vue3-oop'
import { createApp, watchSyncEffect } from 'vue'
import './theme/app.css'
import { CountService } from './count.service'
import { SizeService } from './size.service'
import { Component, Computed, Hook, Mut, VueComponent, VueService } from 'vue3-oop'
import { createApp } from 'vue'

class Child extends VueComponent {
render() {
console.log('render')
return (
<div>
111
<div>{this.context.slots.default?.()}</div>
</div>
)
const debounce = (delay: number) => {
let timeout: number | undefined
return (track: any, trigger: any) => {
let value: any
return {
get() {
track()
return value
},
set(newValue: any) {
clearTimeout(timeout)
timeout = window.setTimeout(() => {
value = newValue
trigger()
}, delay)
},
}
}
}

@Component()
class CountService extends VueService {
@Mut() count = 1
}

class Home extends VueComponent {
constructor(private countService: CountService, private sizeService: SizeService) {
super()
watchSyncEffect(() => this.count > 2)
}
@Mut(debounce(1000)) _count = ''

@Mut() count = 1
@Mut() obj = { name: 123 }

@Computed()
get double() {
return this.count * 2
return this._count
}
set double(val: string) {
this._count = val.toUpperCase()
}
list = new Array(10).fill(1)

@Link() aaa: Child[]

@Hook('Mounted')
mounted() {
console.log(this.aaa)
console.log('mounted')
}

render() {
console.log(this.obj)
console.log('render')
return <input type="text" v-model={this.double} />
}
}

@Component()
class Home1 extends Home {
constructor(private cs: CountService) {
super()
console.log(cs)
}
@Mut() count1 = 111
render() {
return (
<div style={{ textAlign: 'center' }}>
<Child>
<div>11111</div>
</Child>
<h2>count: {this.countService.count}</h2>
<button onClick={() => this.countService.add()}>+</button>
<button onClick={() => this.countService.remove()}>-</button>
<p>
矩形大小: 宽度: {this.sizeService.x} 长度: {this.sizeService.y}
</p>
<div
ref={this.sizeService.target}
style={{
width: '100px',
height: '100px',
resize: 'both',
border: '1px solid #ccc',
overflow: 'scroll',
}}
></div>
<div>
<h5 onClick={() => this.cs.count++}>{this.cs.count}</h5>
<h2 onClick={() => this.count1++}>1111{this.count1}</h2>
{super.render()}
</div>
)
}
}

const app = createApp(Home)
const app = createApp(Home1)
app.mount('#app')
95 changes: 0 additions & 95 deletions example/module/auth/login.view.tsx

This file was deleted.

40 changes: 0 additions & 40 deletions example/module/auth/user.service.ts

This file was deleted.

49 changes: 0 additions & 49 deletions example/module/home/home.view.tsx

This file was deleted.

Loading

0 comments on commit 4cb5239

Please sign in to comment.