test: (wip) test for watch api

This commit is contained in:
Evan You
2019-08-26 22:47:38 -04:00
parent a20eeac7fe
commit d04a4f9cb0
2 changed files with 156 additions and 3 deletions

View File

@@ -81,7 +81,12 @@ function doWatch(
? () => source.map(s => (isRef(s) ? s.value : s()))
: isRef(source)
? () => source.value
: () => source(registerCleanup)
: () => {
if (cleanup) {
cleanup()
}
return source(registerCleanup)
}
const getter = deep ? () => traverse(baseGetter()) : baseGetter
let cleanup: any
@@ -90,7 +95,7 @@ function doWatch(
cleanup = runner.onStop = fn
}
let oldValue: any
let oldValue = isArray(source) ? [] : undefined
const applyCb = cb
? () => {
const newValue = runner()