Skip to content

Commit a078ad1

Browse files
committed
chore: rename handleWarn to onWarn
1 parent 90fd005 commit a078ad1

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

packages/reactivity/__tests__/baseWatch.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ describe('baseWatch', () => {
5353
})
5454

5555
test('custom error handler', () => {
56-
const handleError = vi.fn()
56+
const onError = vi.fn()
5757

5858
baseWatch(
5959
() => {
6060
throw 'oops in effect'
6161
},
6262
null,
63-
{ handleError },
63+
{ onError },
6464
)
6565

6666
const source = ref(0)
@@ -72,26 +72,26 @@ describe('baseWatch', () => {
7272
})
7373
throw 'oops in watch'
7474
},
75-
{ handleError },
75+
{ onError },
7676
)
7777

78-
expect(handleError.mock.calls.length).toBe(1)
79-
expect(handleError.mock.calls[0]).toMatchObject([
78+
expect(onError.mock.calls.length).toBe(1)
79+
expect(onError.mock.calls[0]).toMatchObject([
8080
'oops in effect',
8181
BaseWatchErrorCodes.WATCH_CALLBACK,
8282
])
8383

8484
source.value++
85-
expect(handleError.mock.calls.length).toBe(2)
86-
expect(handleError.mock.calls[1]).toMatchObject([
85+
expect(onError.mock.calls.length).toBe(2)
86+
expect(onError.mock.calls[1]).toMatchObject([
8787
'oops in watch',
8888
BaseWatchErrorCodes.WATCH_CALLBACK,
8989
])
9090

9191
stop()
9292
source.value++
93-
expect(handleError.mock.calls.length).toBe(3)
94-
expect(handleError.mock.calls[2]).toMatchObject([
93+
expect(onError.mock.calls.length).toBe(3)
94+
expect(onError.mock.calls[2]).toMatchObject([
9595
'oops in cleanup',
9696
BaseWatchErrorCodes.WATCH_CLEANUP,
9797
])

packages/reactivity/src/baseWatch.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export interface BaseWatchOptions<Immediate = boolean> extends DebuggerOptions {
7373
deep?: boolean
7474
once?: boolean
7575
scheduler?: Scheduler
76-
handleError?: HandleError
77-
handleWarn?: HandleWarn
76+
onError?: HandleError
77+
onWarn?: HandleWarn
7878
}
7979

8080
type WatchStopHandle = () => void
@@ -121,15 +121,15 @@ export function baseWatch(
121121
immediate,
122122
deep,
123123
once,
124+
scheduler = DEFAULT_SCHEDULER,
125+
onWarn = __DEV__ ? warn : NOOP,
126+
onError = DEFAULT_HANDLE_ERROR,
124127
onTrack,
125128
onTrigger,
126-
scheduler = DEFAULT_SCHEDULER,
127-
handleError: handleError = DEFAULT_HANDLE_ERROR,
128-
handleWarn: handleWarn = __DEV__ ? warn : NOOP,
129129
}: BaseWatchOptions = EMPTY_OBJ,
130130
): WatchInstance {
131131
const warnInvalidSource = (s: unknown) => {
132-
handleWarn(
132+
onWarn(
133133
`Invalid watch source: `,
134134
s,
135135
`A watch source can only be a getter/effect function, a ref, ` +
@@ -161,7 +161,7 @@ export function baseWatch(
161161
} else if (isFunction(s)) {
162162
return callWithErrorHandling(
163163
s,
164-
handleError,
164+
onError,
165165
BaseWatchErrorCodes.WATCH_GETTER,
166166
)
167167
} else {
@@ -172,11 +172,7 @@ export function baseWatch(
172172
if (cb) {
173173
// getter with cb
174174
getter = () =>
175-
callWithErrorHandling(
176-
source,
177-
handleError,
178-
BaseWatchErrorCodes.WATCH_GETTER,
179-
)
175+
callWithErrorHandling(source, onError, BaseWatchErrorCodes.WATCH_GETTER)
180176
} else {
181177
// no cb -> simple effect
182178
getter = () => {
@@ -193,7 +189,7 @@ export function baseWatch(
193189
try {
194190
return callWithAsyncErrorHandling(
195191
source,
196-
handleError,
192+
onError,
197193
BaseWatchErrorCodes.WATCH_CALLBACK,
198194
[onEffectCleanup],
199195
)
@@ -224,7 +220,7 @@ export function baseWatch(
224220
getCurrentScope()?.effects.push((effect = {} as any))
225221
callWithAsyncErrorHandling(
226222
cb,
227-
handleError,
223+
onError,
228224
BaseWatchErrorCodes.WATCH_CALLBACK,
229225
[getter(), isMultiSource ? [] : undefined, onEffectCleanup],
230226
)
@@ -263,7 +259,7 @@ export function baseWatch(
263259
try {
264260
callWithAsyncErrorHandling(
265261
cb,
266-
handleError,
262+
onError,
267263
BaseWatchErrorCodes.WATCH_CALLBACK,
268264
[
269265
newValue,
@@ -306,7 +302,7 @@ export function baseWatch(
306302
cleanups.forEach(cleanup =>
307303
callWithErrorHandling(
308304
cleanup,
309-
handleError,
305+
onError,
310306
BaseWatchErrorCodes.WATCH_CLEANUP,
311307
),
312308
)

packages/runtime-core/src/apiWatch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function doWatch(
198198

199199
const extendOptions: BaseWatchOptions = {}
200200

201-
if (__DEV__) extendOptions.handleWarn = warn
201+
if (__DEV__) extendOptions.onWarn = warn
202202

203203
let ssrCleanup: (() => void)[] | undefined
204204
if (__SSR__ && isInSSRComponentSetup) {
@@ -217,7 +217,7 @@ function doWatch(
217217
const instance =
218218
getCurrentScope() === currentInstance?.scope ? currentInstance : null
219219

220-
extendOptions.handleError = (err: unknown, type: BaseWatchErrorCodes) =>
220+
extendOptions.onError = (err: unknown, type: BaseWatchErrorCodes) =>
221221
handleErrorWithInstance(err, instance, type)
222222

223223
const scheduler = getSchedulerByFlushMode(flush)({ instance })

0 commit comments

Comments
 (0)