Skip to content

Commit d1f001b

Browse files
committed
fix: lint
1 parent 97179ed commit d1f001b

File tree

2 files changed

+67
-63
lines changed

2 files changed

+67
-63
lines changed

packages/reactivity/src/baseWatch.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
import {
22
EMPTY_OBJ,
3-
isObject,
3+
NOOP,
4+
hasChanged,
45
isArray,
56
isFunction,
6-
hasChanged,
7-
NOOP,
87
isMap,
9-
isSet,
8+
isObject,
109
isPlainObject,
11-
isPromise
10+
isPromise,
11+
isSet,
1212
} from '@vue/shared'
1313
import { warn } from './warning'
14-
import { ComputedRef } from './computed'
14+
import type { ComputedRef } from './computed'
1515
import { ReactiveFlags } from './constants'
16-
import { DebuggerOptions, ReactiveEffect, EffectScheduler } from './effect'
17-
import { isShallow, isReactive } from './reactive'
18-
import { Ref, isRef } from './ref'
16+
import {
17+
type DebuggerOptions,
18+
type EffectScheduler,
19+
ReactiveEffect,
20+
} from './effect'
21+
import { isReactive, isShallow } from './reactive'
22+
import { type Ref, isRef } from './ref'
1923
import { getCurrentScope } from './effectScope'
2024

2125
// contexts where user provided function may be executed, in addition to
2226
// lifecycle hooks.
2327
export enum BaseWatchErrorCodes {
2428
WATCH_GETTER = 'BaseWatchErrorCodes_WATCH_GETTER',
2529
WATCH_CALLBACK = 'BaseWatchErrorCodes_WATCH_CALLBACK',
26-
WATCH_CLEANUP = 'BaseWatchErrorCodes_WATCH_CLEANUP'
30+
WATCH_CLEANUP = 'BaseWatchErrorCodes_WATCH_CLEANUP',
2731
}
2832

2933
// TODO move to a scheduler package
@@ -57,7 +61,7 @@ export type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)
5761
export type WatchCallback<V = any, OV = any> = (
5862
value: V,
5963
oldValue: OV,
60-
onCleanup: OnCleanup
64+
onCleanup: OnCleanup,
6165
) => any
6266

6367
type OnCleanup = (cleanupFn: () => void) => void
@@ -119,15 +123,15 @@ export function baseWatch(
119123
onTrigger,
120124
scheduler = DEFAULT_SCHEDULER,
121125
handleError: handleError = DEFAULT_HANDLE_ERROR,
122-
handleWarn: handleWarn = warn
123-
}: BaseWatchOptions = EMPTY_OBJ
126+
handleWarn: handleWarn = warn,
127+
}: BaseWatchOptions = EMPTY_OBJ,
124128
): WatchInstance {
125129
const warnInvalidSource = (s: unknown) => {
126130
handleWarn(
127131
`Invalid watch source: `,
128132
s,
129133
`A watch source can only be a getter/effect function, a ref, ` +
130-
`a reactive object, or an array of these types.`
134+
`a reactive object, or an array of these types.`,
131135
)
132136
}
133137

@@ -156,7 +160,7 @@ export function baseWatch(
156160
return callWithErrorHandling(
157161
s,
158162
handleError,
159-
BaseWatchErrorCodes.WATCH_GETTER
163+
BaseWatchErrorCodes.WATCH_GETTER,
160164
)
161165
} else {
162166
__DEV__ && warnInvalidSource(s)
@@ -169,7 +173,7 @@ export function baseWatch(
169173
callWithErrorHandling(
170174
source,
171175
handleError,
172-
BaseWatchErrorCodes.WATCH_GETTER
176+
BaseWatchErrorCodes.WATCH_GETTER,
173177
)
174178
} else {
175179
// no cb -> simple effect
@@ -184,7 +188,7 @@ export function baseWatch(
184188
source,
185189
handleError,
186190
BaseWatchErrorCodes.WATCH_CALLBACK,
187-
[onEffectCleanup]
191+
[onEffectCleanup],
188192
)
189193
} finally {
190194
activeEffect = currentEffect
@@ -215,7 +219,7 @@ export function baseWatch(
215219
cb,
216220
handleError,
217221
BaseWatchErrorCodes.WATCH_CALLBACK,
218-
[getter(), isMultiSource ? [] : undefined, onEffectCleanup]
222+
[getter(), isMultiSource ? [] : undefined, onEffectCleanup],
219223
)
220224
return NOOP
221225
}
@@ -262,8 +266,8 @@ export function baseWatch(
262266
: isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE
263267
? []
264268
: oldValue,
265-
onEffectCleanup
266-
]
269+
onEffectCleanup,
270+
],
267271
)
268272
oldValue = newValue
269273
} finally {
@@ -284,7 +288,7 @@ export function baseWatch(
284288
scheduler({
285289
effect,
286290
job,
287-
isInit: false
291+
isInit: false,
288292
})
289293

290294
effect = new ReactiveEffect(getter, NOOP, effectScheduler)
@@ -296,8 +300,8 @@ export function baseWatch(
296300
callWithErrorHandling(
297301
cleanup,
298302
handleError,
299-
BaseWatchErrorCodes.WATCH_CLEANUP
300-
)
303+
BaseWatchErrorCodes.WATCH_CLEANUP,
304+
),
301305
)
302306
cleanupMap.delete(effect)
303307
}
@@ -324,7 +328,7 @@ export function baseWatch(
324328
scheduler({
325329
effect,
326330
job,
327-
isInit: true
331+
isInit: true,
328332
})
329333
}
330334

@@ -362,7 +366,7 @@ export function callWithErrorHandling(
362366
fn: Function,
363367
handleError: HandleError,
364368
type: BaseWatchErrorCodes,
365-
args?: unknown[]
369+
args?: unknown[],
366370
) {
367371
let res
368372
try {
@@ -377,7 +381,7 @@ export function callWithAsyncErrorHandling(
377381
fn: Function | Function[],
378382
handleError: HandleError,
379383
type: BaseWatchErrorCodes,
380-
args?: unknown[]
384+
args?: unknown[],
381385
): any[] {
382386
if (isFunction(fn)) {
383387
const res = callWithErrorHandling(fn, handleError, type, args)

packages/runtime-core/src/apiWatch.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
import {
2-
isRef,
3-
type Ref,
2+
type BaseWatchErrorCodes,
3+
type BaseWatchOptions,
44
type ComputedRef,
5-
ReactiveFlags,
65
type DebuggerOptions,
7-
getCurrentScope,
8-
BaseWatchErrorCodes,
6+
ReactiveFlags,
7+
type Ref,
98
baseWatch,
10-
type BaseWatchOptions
9+
getCurrentScope,
10+
isRef,
1111
} from '@vue/reactivity'
1212
import {
1313
type SchedulerJob,
1414
usePreScheduler,
15-
useSyncScheduler
15+
useSyncScheduler,
1616
} from './scheduler'
1717
import {
1818
EMPTY_OBJ,
19-
isObject,
19+
NOOP,
20+
extend,
2021
isArray,
2122
isFunction,
22-
isString,
23-
NOOP,
24-
remove,
2523
isMap,
26-
isSet,
24+
isObject,
2725
isPlainObject,
28-
extend
26+
isSet,
27+
isString,
28+
remove,
2929
} from '@vue/shared'
3030
import {
31-
currentInstance,
3231
type ComponentInternalInstance,
32+
currentInstance,
3333
isInSSRComponentSetup,
3434
setCurrentInstance,
35-
unsetCurrentInstance
35+
unsetCurrentInstance,
3636
} from './component'
3737
import { handleError as handleErrorWithInstance } from './errorHandling'
3838
import { usePostRenderScheduler } from './renderer'
3939
import { warn } from './warning'
40-
import { type ObjectWatchOptionItem } from './componentOptions'
40+
import type { ObjectWatchOptionItem } from './componentOptions'
4141
import { useSSRContext } from '@vue/runtime-core'
4242

4343
export type WatchEffect = (onCleanup: OnCleanup) => void
@@ -47,7 +47,7 @@ export type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)
4747
export type WatchCallback<V = any, OV = any> = (
4848
value: V,
4949
oldValue: OV,
50-
onCleanup: OnCleanup
50+
onCleanup: OnCleanup,
5151
) => any
5252

5353
type MapSources<T, Immediate> = {
@@ -79,30 +79,30 @@ export type WatchStopHandle = () => void
7979
// Simple effect.
8080
export function watchEffect(
8181
effect: WatchEffect,
82-
options?: WatchOptionsBase
82+
options?: WatchOptionsBase,
8383
): WatchStopHandle {
8484
return doWatch(effect, null, options)
8585
}
8686

8787
export function watchPostEffect(
8888
effect: WatchEffect,
89-
options?: DebuggerOptions
89+
options?: DebuggerOptions,
9090
) {
9191
return doWatch(
9292
effect,
9393
null,
94-
__DEV__ ? extend({}, options as any, { flush: 'post' }) : { flush: 'post' }
94+
__DEV__ ? extend({}, options as any, { flush: 'post' }) : { flush: 'post' },
9595
)
9696
}
9797

9898
export function watchSyncEffect(
9999
effect: WatchEffect,
100-
options?: DebuggerOptions
100+
options?: DebuggerOptions,
101101
) {
102102
return doWatch(
103103
effect,
104104
null,
105-
__DEV__ ? extend({}, options as any, { flush: 'sync' }) : { flush: 'sync' }
105+
__DEV__ ? extend({}, options as any, { flush: 'sync' }) : { flush: 'sync' },
106106
)
107107
}
108108

@@ -111,60 +111,60 @@ type MultiWatchSources = (WatchSource<unknown> | object)[]
111111
// overload: array of multiple sources + cb
112112
export function watch<
113113
T extends MultiWatchSources,
114-
Immediate extends Readonly<boolean> = false
114+
Immediate extends Readonly<boolean> = false,
115115
>(
116116
sources: [...T],
117117
cb: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>,
118-
options?: WatchOptions<Immediate>
118+
options?: WatchOptions<Immediate>,
119119
): WatchStopHandle
120120

121121
// overload: multiple sources w/ `as const`
122122
// watch([foo, bar] as const, () => {})
123123
// somehow [...T] breaks when the type is readonly
124124
export function watch<
125125
T extends Readonly<MultiWatchSources>,
126-
Immediate extends Readonly<boolean> = false
126+
Immediate extends Readonly<boolean> = false,
127127
>(
128128
source: T,
129129
cb: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>,
130-
options?: WatchOptions<Immediate>
130+
options?: WatchOptions<Immediate>,
131131
): WatchStopHandle
132132

133133
// overload: single source + cb
134134
export function watch<T, Immediate extends Readonly<boolean> = false>(
135135
source: WatchSource<T>,
136136
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
137-
options?: WatchOptions<Immediate>
137+
options?: WatchOptions<Immediate>,
138138
): WatchStopHandle
139139

140140
// overload: watching reactive object w/ cb
141141
export function watch<
142142
T extends object,
143-
Immediate extends Readonly<boolean> = false
143+
Immediate extends Readonly<boolean> = false,
144144
>(
145145
source: T,
146146
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
147-
options?: WatchOptions<Immediate>
147+
options?: WatchOptions<Immediate>,
148148
): WatchStopHandle
149149

150150
// implementation
151151
export function watch<T = any, Immediate extends Readonly<boolean> = false>(
152152
source: T | WatchSource<T>,
153153
cb: any,
154-
options?: WatchOptions<Immediate>
154+
options?: WatchOptions<Immediate>,
155155
): WatchStopHandle {
156156
if (__DEV__ && !isFunction(cb)) {
157157
warn(
158158
`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
159159
`Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
160-
`supports \`watch(source, cb, options?) signature.`
160+
`supports \`watch(source, cb, options?) signature.`,
161161
)
162162
}
163163
return doWatch(source as any, cb, options)
164164
}
165165

166166
function getSchedulerByFlushMode(
167-
flush: WatchOptionsBase['flush']
167+
flush: WatchOptionsBase['flush'],
168168
): SchedulerJob {
169169
if (flush === 'post') {
170170
return usePostRenderScheduler
@@ -179,26 +179,26 @@ function getSchedulerByFlushMode(
179179
function doWatch(
180180
source: WatchSource | WatchSource[] | WatchEffect | object,
181181
cb: WatchCallback | null,
182-
options: WatchOptions = EMPTY_OBJ
182+
options: WatchOptions = EMPTY_OBJ,
183183
): WatchStopHandle {
184184
const { immediate, deep, flush, once } = options
185185
if (__DEV__ && !cb) {
186186
if (immediate !== undefined) {
187187
warn(
188188
`watch() "immediate" option is only respected when using the ` +
189-
`watch(source, callback, options?) signature.`
189+
`watch(source, callback, options?) signature.`,
190190
)
191191
}
192192
if (deep !== undefined) {
193193
warn(
194194
`watch() "deep" option is only respected when using the ` +
195-
`watch(source, callback, options?) signature.`
195+
`watch(source, callback, options?) signature.`,
196196
)
197197
}
198198
if (once !== undefined) {
199199
warn(
200200
`watch() "once" option is only respected when using the ` +
201-
`watch(source, callback, options?) signature.`
201+
`watch(source, callback, options?) signature.`,
202202
)
203203
}
204204
}
@@ -246,7 +246,7 @@ export function instanceWatch(
246246
this: ComponentInternalInstance,
247247
source: string | Function,
248248
value: WatchCallback | ObjectWatchOptionItem,
249-
options?: WatchOptions
249+
options?: WatchOptions,
250250
): WatchStopHandle {
251251
const publicThis = this.proxy as any
252252
const getter = isString(source)

0 commit comments

Comments
 (0)