Skip to content

Commit

Permalink
chore: fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 6, 2022
1 parent 41ed212 commit 0ef0b5e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/shared/watchArray/index.ts
Expand Up @@ -9,15 +9,20 @@ export declare type WatchArrayCallback<V = any, OV = any> = (value: V, oldValue:
* @see https://vueuse.org/watchArray
*/
export function watchArray<T, Immediate extends Readonly<boolean> = false>(
source: WatchSource<T[]>,
source: WatchSource<T[]> | T[],
cb: WatchArrayCallback<T[], Immediate extends true ? T[] | undefined : T[]>,
options?: WatchOptions<Immediate>,
) {
let oldList: T[] = options?.immediate
? []
: [...(source instanceof Function ? source() : unref(source))]
: [...(source instanceof Function
? source()
: Array.isArray(source)
? source
: unref(source)),
]

return watch(source, (newList, _, onCleanup) => {
return watch(source as WatchSource<T[]>, (newList, _, onCleanup) => {
const oldListRemains = new Array<boolean>(oldList.length)
const added: T[] = []
for (const obj of newList) {
Expand Down

0 comments on commit 0ef0b5e

Please sign in to comment.