Skip to content

Commit 384591a

Browse files
types: make instrumentations' types more succinct (#8558)
Co-authored-by: Haoqun Jiang <haoqunjiang@gmail.com>
1 parent d46df6b commit 384591a

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

packages/reactivity/src/collectionHandlers.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ function createReadonlyMethod(type: TriggerOpTypes): Function {
237237
}
238238
}
239239

240+
type Instrumentations = Record<string | symbol, Function | number>
241+
240242
function createInstrumentations() {
241-
const mutableInstrumentations: Record<string, Function | number> = {
243+
const mutableInstrumentations: Instrumentations = {
242244
get(this: MapTypes, key: unknown) {
243245
return get(this, key)
244246
},
@@ -253,7 +255,7 @@ function createInstrumentations() {
253255
forEach: createForEach(false, false),
254256
}
255257

256-
const shallowInstrumentations: Record<string, Function | number> = {
258+
const shallowInstrumentations: Instrumentations = {
257259
get(this: MapTypes, key: unknown) {
258260
return get(this, key, false, true)
259261
},
@@ -268,7 +270,7 @@ function createInstrumentations() {
268270
forEach: createForEach(false, true),
269271
}
270272

271-
const readonlyInstrumentations: Record<string, Function | number> = {
273+
const readonlyInstrumentations: Instrumentations = {
272274
get(this: MapTypes, key: unknown) {
273275
return get(this, key, true)
274276
},
@@ -285,7 +287,7 @@ function createInstrumentations() {
285287
forEach: createForEach(true, false),
286288
}
287289

288-
const shallowReadonlyInstrumentations: Record<string, Function | number> = {
290+
const shallowReadonlyInstrumentations: Instrumentations = {
289291
get(this: MapTypes, key: unknown) {
290292
return get(this, key, true, true)
291293
},
@@ -302,24 +304,18 @@ function createInstrumentations() {
302304
forEach: createForEach(true, true),
303305
}
304306

305-
const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator]
307+
const iteratorMethods = [
308+
'keys',
309+
'values',
310+
'entries',
311+
Symbol.iterator,
312+
] as const
313+
306314
iteratorMethods.forEach(method => {
307-
mutableInstrumentations[method as string] = createIterableMethod(
308-
method,
309-
false,
310-
false,
311-
)
312-
readonlyInstrumentations[method as string] = createIterableMethod(
313-
method,
314-
true,
315-
false,
316-
)
317-
shallowInstrumentations[method as string] = createIterableMethod(
318-
method,
319-
false,
320-
true,
321-
)
322-
shallowReadonlyInstrumentations[method as string] = createIterableMethod(
315+
mutableInstrumentations[method] = createIterableMethod(method, false, false)
316+
readonlyInstrumentations[method] = createIterableMethod(method, true, false)
317+
shallowInstrumentations[method] = createIterableMethod(method, false, true)
318+
shallowReadonlyInstrumentations[method] = createIterableMethod(
323319
method,
324320
true,
325321
true,

0 commit comments

Comments
 (0)