( vm: ComponentInstance, source: WatchSource | WatchSource[] | WatchEffect, cb: WatchCallback | null, options: WatchOptions )
| 201 | } |
| 202 | |
| 203 | function createWatcher( |
| 204 | vm: ComponentInstance, |
| 205 | source: WatchSource | WatchSource[] | WatchEffect, |
| 206 | cb: WatchCallback | null, |
| 207 | options: WatchOptions |
| 208 | ): () => void { |
| 209 | if (__DEV__ && !cb) { |
| 210 | if (options.immediate !== undefined) { |
| 211 | warn( |
| 212 | `watch() "immediate" option is only respected when using the ` + |
| 213 | `watch(source, callback, options?) signature.` |
| 214 | ) |
| 215 | } |
| 216 | if (options.deep !== undefined) { |
| 217 | warn( |
| 218 | `watch() "deep" option is only respected when using the ` + |
| 219 | `watch(source, callback, options?) signature.` |
| 220 | ) |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | const flushMode = options.flush |
| 225 | const isSync = flushMode === 'sync' |
| 226 | let cleanup: (() => void) | null |
| 227 | const registerCleanup: InvalidateCbRegistrator = (fn: () => void) => { |
| 228 | cleanup = () => { |
| 229 | try { |
| 230 | fn() |
| 231 | } catch ( |
| 232 | // FIXME: remove any |
| 233 | error: any |
| 234 | ) { |
| 235 | logError(error, vm, 'onCleanup()') |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | // cleanup before running getter again |
| 240 | const runCleanup = () => { |
| 241 | if (cleanup) { |
| 242 | cleanup() |
| 243 | cleanup = null |
| 244 | } |
| 245 | } |
| 246 | const createScheduler = <T extends Function>(fn: T): T => { |
| 247 | if ( |
| 248 | isSync || |
| 249 | /* without a current active instance, ignore pre|post mode */ vm === |
| 250 | fallbackVM |
| 251 | ) { |
| 252 | return fn |
| 253 | } |
| 254 | return ((...args: any[]) => |
| 255 | queueFlushJob( |
| 256 | vm, |
| 257 | () => { |
| 258 | fn(...args) |
| 259 | }, |
| 260 | flushMode as 'pre' | 'post' |
no test coverage detected
searching dependent graphs…