From b053abd596a2c2bdf3c9aa7c06412177814fcc51 Mon Sep 17 00:00:00 2001 From: daishi Date: Wed, 1 Dec 2021 07:04:45 +0900 Subject: [PATCH] fix(utils): add watch options for notify-in-sync --- src/utils/watch.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils/watch.ts b/src/utils/watch.ts index 69969dda..5251baa5 100644 --- a/src/utils/watch.ts +++ b/src/utils/watch.ts @@ -2,6 +2,9 @@ import { subscribe } from '../vanilla' type WatchGet = (value: T) => T type WatchCallback = (get: WatchGet) => (() => void) | void | undefined +type WatchOptions = { + sync?: boolean +} let currentCleanups: Set<() => void> | undefined @@ -28,7 +31,10 @@ let currentCleanups: Set<() => void> | undefined * @returns A cleanup function that stops the callback from reevaluating and * also performs cleanups registered into `watch`. */ -export const watch = (callback: WatchCallback): (() => void) => { +export const watch = ( + callback: WatchCallback, + options?: WatchOptions +): (() => void) => { const cleanups = new Set<() => void>() const subscriptions = new Set() @@ -72,7 +78,7 @@ export const watch = (callback: WatchCallback): (() => void) => { // Subscribe to all collected proxies subscriptions.forEach((proxy) => { - const clean = subscribe(proxy, revalidate) + const clean = subscribe(proxy, revalidate, options?.sync) cleanups.add(clean) }) }