Skip to content

Commit 28f568e

Browse files
committed
refactor: 格式化代码
1 parent 8fcbcb4 commit 28f568e

File tree

21 files changed

+97
-258
lines changed

21 files changed

+97
-258
lines changed

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ export default defineConfig({
2424
'@typescript-eslint/no-explicit-any': 'off',
2525
'@typescript-eslint/no-floating-promises': 'off',
2626
'require-await': 'warn',
27+
'@typescript-eslint/no-useless-constructor': 'warn',
28+
'@typescript-eslint/no-unsafe-function-type': 'warn',
2729
},
2830
})

playground/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"vite": "^6.2.4",
2020
"typescript": "^5.8.2",
2121
"vite-plugin-tsconfig-paths": "^1.4.1",
22-
"@vue3-oop/plugin-vue-jsx": "^1.4.6"
22+
"@vue3-oop/plugin-vue-jsx": "^1.4.6",
23+
"@vue/runtime-dom": "^3.5.13"
2324
}
2425
}

playground/src/common/directive/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { App, Directive } from 'vue'
66
const dirs = import.meta.glob('./**/*.directive.ts', { eager: true })
77

88
export function setupDirective(app: App) {
9-
Reflect.ownKeys(dirs).forEach((k) => {
9+
Reflect.ownKeys(dirs).forEach(k => {
1010
const module: any = dirs[k as string]
1111
if (!module?.default) return
1212
const dir = module.default as Directive & { name: string }

playground/src/main.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,14 @@ class App extends VueComponent {
4444
VUE 示例
4545
</h2>
4646
<Menu theme={'dark'} mode={'inline'}>
47-
{routes.map((r) => {
47+
{routes.map(r => {
4848
return (
4949
<Menu.SubMenu title={r.meta?.title} key={r.path}>
5050
{'children' in r &&
51-
r.children?.map((i) => {
51+
r.children?.map(i => {
5252
return (
5353
<Menu.Item key={i.path}>
54-
<RouterLink
55-
to={i.path}
56-
style={{ display: 'block' }}
57-
>
54+
<RouterLink to={i.path} style={{ display: 'block' }}>
5855
{i.meta?.title}
5956
</RouterLink>
6057
</Menu.Item>

playground/src/module/basic/hello-world/a.comp.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
import {
2-
Autobind,
3-
Component,
4-
type ComponentProps,
5-
Computed,
6-
Hook,
7-
Mut,
8-
VueComponent,
9-
VueService,
10-
} from 'vue3-oop'
1+
import { Autobind, Component, type ComponentProps, Computed, Hook, Mut, VueComponent, VueService } from 'vue3-oop'
112
import type { VNodeChild } from 'vue'
123
import { Injectable } from 'injection-js'
134

playground/src/module/basic/hello-world/hello-world.view.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Hook, injectService, Link, 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'
3+
import { RouterService } from '@/router/router.service'
54

65
export class Base extends VueComponent {
76
@Mut() count = 1
@@ -14,13 +13,16 @@ function Foo() {
1413
return <div v-focus>aaaaaaa</div>
1514
}
1615

16+
declare module '@vue/runtime-dom' {
17+
interface HTMLAttributes {
18+
onClickOnce?: () => void
19+
'v-focus'?: any
20+
}
21+
}
22+
1723
export class Child1 extends Base {
1824
render() {
19-
return (
20-
<div onClick={withModifiers(() => this.count++, ['once'])}>
21-
{super.render()}
22-
</div>
23-
)
25+
return <div onClickOnce={() => this.count++}>{super.render()}</div>
2426
}
2527
}
2628

@@ -39,7 +41,7 @@ export default class HelloWorldView extends VueComponent {
3941
@Mut() count = 1
4042

4143
async init() {
42-
await new Promise((r) => setTimeout(r, 5000))
44+
await new Promise(r => setTimeout(r, 5000))
4345
}
4446

4547
router = injectService(RouterService)!
@@ -59,10 +61,7 @@ export default class HelloWorldView extends VueComponent {
5961
<Button type={'primary'} onClick={() => this.count++} ref={'abc'}>
6062
+
6163
</Button>
62-
<Input
63-
v-model:value={this.count}
64-
style={{ width: '100px', textAlign: 'center' }}
65-
></Input>
64+
<Input v-model:value={this.count} style={{ width: '100px', textAlign: 'center' }}></Input>
6665
<Button type={'primary'} onClick={() => this.count--}>
6766
-
6867
</Button>

playground/src/module/basic/hoc/hoc.view.tsx

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
type ComponentProps,
3-
Hook,
4-
Link,
5-
Mut,
6-
useForwardRef,
7-
VueComponent,
8-
} from 'vue3-oop'
1+
import { type ComponentProps, Hook, Link, Mut, useForwardRef, VueComponent } from 'vue3-oop'
92
import { nextTick } from 'vue'
103
import { Card } from 'ant-design-vue'
114

@@ -25,7 +18,7 @@ class Origin extends VueComponent<OriginProps> {
2518
return (
2619
<div>
2720
<h2 onClick={() => this.count++}>{this.count}</h2>
28-
{props.data?.map((k) => <li key={k}>{k}</li>) || <div>nodata</div>}
21+
{props.data?.map(k => <li key={k}>{k}</li>) || <div>nodata</div>}
2922
</div>
3023
)
3124
}
@@ -43,7 +36,7 @@ class OriginWithData extends Origin {
4336
// 自带请求数据的组件
4437
function WithDataOrigin<T extends { new (...args: any[]): any }>(
4538
Comp: T,
46-
request: (...args: any[]) => Promise<number[]>
39+
request: (...args: any[]) => Promise<number[]>,
4740
): T {
4841
class CompWithData extends VueComponent {
4942
// 处理属性
@@ -64,14 +57,7 @@ function WithDataOrigin<T extends { new (...args: any[]): any }>(
6457

6558
render() {
6659
if (!this.data) return <div>loading....</div>
67-
return (
68-
<Comp
69-
ref={this.forwardRef}
70-
{...this.context.attrs}
71-
data={this.data}
72-
v-slots={this.context.slots}
73-
></Comp>
74-
)
60+
return <Comp ref={this.forwardRef} {...this.context.attrs} data={this.data} v-slots={this.context.slots}></Comp>
7561
}
7662
}
7763

@@ -81,7 +67,7 @@ function WithDataOrigin<T extends { new (...args: any[]): any }>(
8167
// 自带请求数据的组件
8268
function WithDataOriginExtends<T extends { new (...args: any[]): any }>(
8369
Comp: T,
84-
request: (...args: any[]) => Promise<number[]>
70+
request: (...args: any[]) => Promise<number[]>,
8571
): T {
8672
class CompWithData extends Comp {
8773
@Mut() data?: number[]
@@ -103,9 +89,9 @@ function WithDataOriginExtends<T extends { new (...args: any[]): any }>(
10389
const OriginData = WithDataOriginExtends(
10490
Origin,
10591
() =>
106-
new Promise((resolve) => {
92+
new Promise(resolve => {
10793
setTimeout(() => resolve([1, 2, 3]), 3000)
108-
})
94+
}),
10995
)
11096

11197
export default class HocView extends VueComponent {

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/decorators/computed.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ export interface ComputedDecorator {
1616
}
1717

1818
function handler(targetThis: Record<any, any>) {
19-
const list = getProtoMetadata<EagerType>(
20-
targetThis,
21-
Computed.MetadataKey,
22-
true,
23-
)
19+
const list = getProtoMetadata<EagerType>(targetThis, Computed.MetadataKey, true)
2420
if (!list || !list.length) return
2521
for (const item of list) {
2622
const desc = item.desc

src/decorators/hook.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ export interface HookDecorator {
3737
}
3838

3939
function handler(targetThis: any) {
40-
const list = getProtoMetadata<(Lifecycle | Lifecycle[])[]>(
41-
targetThis,
42-
Hook.MetadataKey,
43-
)
40+
const list = getProtoMetadata<(Lifecycle | Lifecycle[])[]>(targetThis, Hook.MetadataKey)
4441
if (!list?.length) return
4542
for (const item of list) {
4643
let vueFn: any

src/decorators/link.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ export interface LinkDecorator {
99
}
1010

1111
function handler(targetThis: Record<any, any>) {
12-
const list = getProtoMetadata<string | undefined>(
13-
targetThis,
14-
Link.MetadataKey,
15-
)
12+
const list = getProtoMetadata<string | undefined>(targetThis, Link.MetadataKey)
1613
if (!list || !list.length) return
1714
for (const item of list) {
1815
const { key, options } = item

src/decorators/mut.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@ export const Mut: MutDecorator = createDecorator<MutOptions>('Mut')
88
type MutOptions = void | true | Parameters<typeof customRef>[0]
99
type RefFactory = Parameters<typeof customRef>[0]
1010
export interface MutDecorator {
11-
(): PropertyDecorator
1211
/**
13-
* @param shallow 是否是浅层响应式
12+
* @param shallowOrRefFactory
1413
*/
15-
(shallow: true): PropertyDecorator
16-
/**
17-
* 自定义ref 的实现
18-
* @param refFactory
19-
*/
20-
(refFactory: RefFactory): PropertyDecorator
14+
(shallowOrRefFactory?: true | RefFactory): PropertyDecorator
2115
MetadataKey: string | symbol
2216
}
2317

@@ -30,11 +24,7 @@ function handler(targetThis: Record<string | symbol, any>) {
3024
}
3125
}
3226

33-
export function defMut(
34-
targetThis: Record<string | symbol, any>,
35-
key: string | symbol,
36-
options: any,
37-
) {
27+
export function defMut(targetThis: Record<string | symbol, any>, key: string | symbol, options: any) {
3828
let keyVal: Ref
3929
if (options === true) {
4030
keyVal = shallowRef()

src/decorators/util.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ export function createDecorator<T = void>(name: string, allowRepeat = false) {
1515
const MetadataKey = createSymbol(metaName)
1616
const decoratorFn: DecoratorFn<T> = function (options: T) {
1717
return function (target: any, key: string | symbol) {
18-
let list: MetadataStore<T | T[]>[] =
19-
Reflect.getMetadata(MetadataKey, target) || []
18+
let list: MetadataStore<T | T[]>[] = Reflect.getMetadata(MetadataKey, target) || []
2019
// 处理继承
2120
list = list.slice()
22-
const hasIndex = list.findIndex((k) => k.key === key)
21+
const hasIndex = list.findIndex(k => k.key === key)
2322
if (hasIndex === -1) {
2423
list.push({ key, options: allowRepeat ? [options] : options })
2524
} else {
@@ -43,23 +42,16 @@ export function createDecorator<T = void>(name: string, allowRepeat = false) {
4342
})
4443
return decoratorFn
4544
}
46-
export function getProtoMetadata<T = void>(
47-
target: any,
48-
key: symbol | string,
49-
withDesc = false,
50-
): MetadataStore<T>[] {
45+
export function getProtoMetadata<T = void>(target: any, key: symbol | string, withDesc = false): MetadataStore<T>[] {
5146
const proto = Object.getPrototypeOf(target)
5247
if (!proto) return []
5348
const res: MetadataStore<any>[] = Reflect.getMetadata(key, proto) || []
5449
if (withDesc) {
55-
res.forEach((k) => (k.desc = getDeepOwnDescriptor(proto, k.key)))
50+
res.forEach(k => (k.desc = getDeepOwnDescriptor(proto, k.key)))
5651
}
5752
return res
5853
}
59-
export function getDeepOwnDescriptor(
60-
proto: any,
61-
key: string | symbol,
62-
): PropertyDescriptor | null {
54+
export function getDeepOwnDescriptor(proto: any, key: string | symbol): PropertyDescriptor | null {
6355
if (!proto) return null
6456
const desc = Object.getOwnPropertyDescriptor(proto, key)
6557
if (desc) return desc

0 commit comments

Comments
 (0)