Skip to content

Commit 584d77b

Browse files
GodD6366小翊temu.psc
authored
feat: 新增 setUpdatePerformanceListener 类型 & lint hook (#25)
Co-authored-by: 小翊 <[email protected]> Co-authored-by: temu.psc <[email protected]>
1 parent 86ba6e3 commit 584d77b

File tree

9 files changed

+194
-116
lines changed

9 files changed

+194
-116
lines changed

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@
1313
"disttag:release": "sh ./scripts/set-release-tag.sh",
1414
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
1515
"test": "jest",
16-
"ci": "yarn test"
16+
"ci": "yarn test",
17+
"lint": "prettier -w .",
18+
"prepare": "husky install"
19+
},
20+
"lint-staged": {
21+
"*.d.ts": [
22+
"prettier --config ./.prettierrc --write"
23+
]
1724
},
1825
"devDependencies": {
1926
"@tsd/typescript": "^4.7.4",
2027
"conventional-changelog-cli": "^2.2.2",
28+
"husky": "^8.0.3",
2129
"jest": "^28.1.1",
2230
"jest-runner-tsd": "^3.1.0",
2331
"lerna": "^5.0.0",
32+
"lint-staged": "^13.1.0",
33+
"prettier": "^2.8.1",
2434
"typescript": "^4.6.4"
2535
}
2636
}

packages/global/types/index.d.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ declare namespace MiniProgram {
3333
type TGetMixinProps<T> = T extends { props: infer P } ? P : never;
3434

3535
// 整合一下类型
36-
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (
37-
x: infer R
38-
) => any
36+
type UnionToIntersection<T> = (
37+
T extends any ? (x: T) => any : never
38+
) extends (x: infer R) => any
3939
? R
4040
: never;
4141

@@ -54,14 +54,14 @@ declare namespace MiniProgram {
5454
* Recursively map a type and make all properties optional & dynamic.
5555
*/
5656
type RecursivePartialAndDynamic<T> = T extends object
57-
? {
58-
[P in keyof T]?: T[P] extends Array<infer U>
59-
? Array<RecursivePartialAndDynamic<U>>
60-
: T[P] extends Function
61-
? T[P]
62-
: T[P] extends object
63-
? RecursivePartialAndDynamic<T[P]>
64-
: T[P];
65-
}
66-
: T;
57+
? {
58+
[P in keyof T]?: T[P] extends Array<infer U>
59+
? Array<RecursivePartialAndDynamic<U>>
60+
: T[P] extends Function
61+
? T[P]
62+
: T[P] extends object
63+
? RecursivePartialAndDynamic<T[P]>
64+
: T[P];
65+
}
66+
: T;
6767
}

packages/global/types/lib.app.d.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ declare namespace MiniProgram.App {
9090
/**
9191
* Additional properties in App instance, for module augmentation
9292
*/
93-
interface IInstanceAdditionalProperties<
94-
ExtraOptions extends UnknownRecord
95-
> {}
93+
interface IInstanceAdditionalProperties<ExtraOptions extends UnknownRecord> {}
9694

9795
/**
9896
* App 的类型
@@ -111,10 +109,9 @@ declare namespace MiniProgram.App {
111109
/**
112110
* 用户可配置的 App Options
113111
*/
114-
type UserAppOptions<
115-
ExtraThis,
116-
ExtraOptions extends UnknownRecord
117-
> = Partial<Options<ExtraOptions>> &
112+
type UserAppOptions<ExtraThis, ExtraOptions extends UnknownRecord> = Partial<
113+
Options<ExtraOptions>
114+
> &
118115
Partial<
119116
UniqueLeft<UniqueLeft<ExtraThis, ExtraOptions>, Options<ExtraOptions>>
120117
> & {
@@ -124,10 +121,7 @@ declare namespace MiniProgram.App {
124121
} & ThisType<IAppInstance<ExtraThis, ExtraOptions>>;
125122

126123
interface Constructor {
127-
<
128-
ExtraThis = {},
129-
ExtraOptions extends Record<string, unknown> = {}
130-
>(
124+
<ExtraThis = {}, ExtraOptions extends Record<string, unknown> = {}>(
131125
opts: UserAppOptions<
132126
ExtraThis & IGlobalMiniProgramExtraThis4App,
133127
ExtraOptions
@@ -139,6 +133,9 @@ declare namespace MiniProgram.App {
139133
<
140134
ExtraThis = {},
141135
ExtraOptions extends Record<string, unknown> = {}
142-
>(): IAppInstance<ExtraThis & IGlobalMiniProgramExtraThis4App, ExtraOptions>
136+
>(): IAppInstance<
137+
ExtraThis & IGlobalMiniProgramExtraThis4App,
138+
ExtraOptions
139+
>;
143140
}
144-
}
141+
}

packages/global/types/lib.component.d.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,6 @@ declare namespace MiniProgram.Component {
6767
orientation?: 'landscape' | 'portrait';
6868
}
6969

70-
interface SetUpdatePerformanceListenerOption<WithDataPath extends boolean> {
71-
/**
72-
* 是否返回变更的 data 字段信息
73-
*/
74-
withDataPaths?: WithDataPath;
75-
}
76-
77-
interface UpdatePerformanceListener<WithDataPath> {
78-
(res: UpdatePerformance<WithDataPath>): void;
79-
}
80-
81-
interface UpdatePerformance<WithDataPath> {
82-
// TODO
83-
}
84-
8570
interface ILifetimes {
8671
/**
8772
* 在组件实例刚刚被创建时执行
@@ -459,12 +444,12 @@ declare namespace MiniProgram.Component {
459444
*/
460445
hasMixin(mixin: Mixin.IMixinIdentifier): boolean;
461446
/**
462-
* 获取更新性能统计信息
447+
* 监听 setData 引发界面更新的开销,参见 获取更新性能统计信息
463448
* @version 2.8.5
464449
*/
465450
setUpdatePerformanceListener<WithDataPath extends boolean = false>(
466-
option: SetUpdatePerformanceListenerOption<WithDataPath>,
467-
callback?: UpdatePerformanceListener<WithDataPath>
451+
option: Shared.SetUpdatePerformanceListenerOption<WithDataPath>,
452+
callback?: Shared.UpdatePerformanceListener<WithDataPath>
468453
): void;
469454
}
470455

@@ -551,11 +536,20 @@ declare namespace MiniProgram.Component {
551536
Methods = {},
552537
ExtraThis = {},
553538
ExtraOptions extends Record<string, unknown> = {},
554-
Mixins extends Array<Mixin.IMixin4Legacy | ReturnType<Mixin.Constructor>> = any[]
539+
Mixins extends Array<
540+
Mixin.IMixin4Legacy | ReturnType<Mixin.Constructor>
541+
> = any[]
555542
>(
556543
opts: Partial<IOptions<Data, Props, Methods, ExtraOptions, Mixins>> &
557544
ThisType<
558-
IInstance<Data, Props, Methods, ExtraThis & IGlobalMiniProgramExtraThis4Component, ExtraOptions, Mixins>
545+
IInstance<
546+
Data,
547+
Props,
548+
Methods,
549+
ExtraThis & IGlobalMiniProgramExtraThis4Component,
550+
ExtraOptions,
551+
Mixins
552+
>
559553
>
560554
): void;
561555
}

packages/global/types/lib.global.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export type IAppOnLaunchOptions<Query extends Record<string, string>> = MiniProgram.App.LaunchOptions<Query>;
1+
export type IAppOnLaunchOptions<Query extends Record<string, string>> =
2+
MiniProgram.App.LaunchOptions<Query>;
23
export interface IRequirePlugin<
34
Target extends Record<string, any> = Record<string, any>
45
> {
@@ -49,7 +50,7 @@ declare global {
4950
* Page's constructor
5051
* @link https://opendocs.alipay.com/mini/framework/page-detail
5152
*/
52-
const Page: MiniProgram.Page.Constructor
53+
const Page: MiniProgram.Page.Constructor;
5354

5455
/**
5556
* Component's constructor
@@ -62,6 +63,5 @@ declare global {
6263
* @version 2.8.2
6364
* @link https://opendocs.alipay.com/mini/05bchn
6465
*/
65-
const Mixin: MiniProgram.Mixin.Constructor
66+
const Mixin: MiniProgram.Mixin.Constructor;
6667
}
67-

packages/global/types/lib.mixin.d.ts

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,34 @@ declare namespace MiniProgram.Mixin {
22
/**
33
* 传统的组件间代码复用,仅Component的mixins参数支持传入,Mixin参数mixins 则只支持传入Mixin()的返回值
44
*/
5-
type IMixin4Legacy = Partial<Omit<Component.IOptions<UnknownRecord, UnknownRecord, UnknownRecord, UnknownRecord, []>, 'ref' | 'options' | 'mixins' | 'externalClasses'>>;
5+
type IMixin4Legacy = Partial<
6+
Omit<
7+
Component.IOptions<
8+
UnknownRecord,
9+
UnknownRecord,
10+
UnknownRecord,
11+
UnknownRecord,
12+
[]
13+
>,
14+
'ref' | 'options' | 'mixins' | 'externalClasses'
15+
>
16+
>;
617
/**
718
* Mixin() 返回值
819
*/
920
type IMixinIdentifier = string;
1021

11-
type IMixinDefinitionFilter = <T extends Component.IOptions<any, any, any, any, any> | IMixinOptions<any, any, any, any, any, any> | Page.IOptions<any, any>>(
22+
type IMixinDefinitionFilter = <
23+
T extends
24+
| Component.IOptions<any, any, any, any, any>
25+
| IMixinOptions<any, any, any, any, any, any>
26+
| Page.IOptions<any, any>
27+
>(
1228
/** 使用该 mixin 的 component/mixin 的定义对象 */
1329
defFields: T,
1430
/** 该 mixin 所使用的 mixin 的 definitionFilter 函数列表 */
1531
definitionFilterArr?: IMixinDefinitionFilter[] | void
16-
) => void
32+
) => void;
1733

1834
/**
1935
* Mixin构造器参数
@@ -25,29 +41,39 @@ declare namespace MiniProgram.Mixin {
2541
ExtraThis,
2642
ExtraOptions extends UnknownRecord,
2743
Mixins extends Array<ReturnType<Constructor>>
28-
> = {
29-
[P in keyof ExtraOptions]: P extends keyof Component.IOptions<
30-
Data,
31-
Props,
32-
Methods,
33-
ExtraOptions,
34-
Mixins
35-
> | 'definitionFilter' | 'mixins'
44+
> = {
45+
[P in keyof ExtraOptions]: P extends
46+
| keyof Component.IOptions<Data, Props, Methods, ExtraOptions, Mixins>
47+
| 'definitionFilter'
48+
| 'mixins'
3649
? unknown
3750
: ExtraOptions[P];
38-
} & Omit<Partial<Component.IOptions<Data, Props, Methods, ExtraOptions, IMixinIdentifier[]>>, 'ref' | 'options' | 'externalClasses'> & Partial<{
39-
/**
40-
* 定义段过滤器,用于自定义组件扩展
41-
*/
42-
definitionFilter: IMixinDefinitionFilter,
51+
} & Omit<
52+
Partial<
53+
Component.IOptions<Data, Props, Methods, ExtraOptions, IMixinIdentifier[]>
54+
>,
55+
'ref' | 'options' | 'externalClasses'
56+
> &
57+
Partial<{
58+
/**
59+
* 定义段过滤器,用于自定义组件扩展
60+
*/
61+
definitionFilter: IMixinDefinitionFilter;
4362
/**
44-
* 组件间代码复用,用于Mixin()的mixins 只支持传入Mixin()注册生成的返回值。不支持传入 js Object
45-
*/
46-
mixins: Mixins
63+
* 组件间代码复用,用于Mixin()的mixins 只支持传入Mixin()注册生成的返回值。不支持传入 js Object
64+
*/
65+
mixins: Mixins;
4766
}> &
4867
ThisType<
49-
Component.IInstance<Data, Props, Methods, ExtraThis, ExtraOptions, IMixinIdentifier[]>
50-
>;
68+
Component.IInstance<
69+
Data,
70+
Props,
71+
Methods,
72+
ExtraThis,
73+
ExtraOptions,
74+
IMixinIdentifier[]
75+
>
76+
>;
5177

5278
interface Constructor {
5379
<
@@ -57,13 +83,15 @@ declare namespace MiniProgram.Mixin {
5783
ExtraThis = {},
5884
ExtraOptions extends Record<string, unknown> = {},
5985
Mixins extends IMixinIdentifier[] = IMixinIdentifier[]
60-
>(options: IMixinOptions<
61-
Data,
62-
Props,
63-
Methods,
64-
ExtraThis & IGlobalMiniProgramExtraThis4Component,
65-
ExtraOptions,
66-
Mixins
67-
>): IMixinIdentifier;
86+
>(
87+
options: IMixinOptions<
88+
Data,
89+
Props,
90+
Methods,
91+
ExtraThis & IGlobalMiniProgramExtraThis4Component,
92+
ExtraOptions,
93+
Mixins
94+
>
95+
): IMixinIdentifier;
6896
}
6997
}

0 commit comments

Comments
 (0)