8000 pref(watchIgnorable): remove additional responsive ref by doyuli · Pull Request #4807 · vueuse/vueuse · GitHub
[go: up one dir, main page]

Skip to content

pref(watchIgnorable): remove additional responsive ref #4807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
pref(watchIgnorable): remove additional responsive ref
  • Loading branch information
doyuli authored Jun 9, 2025
commit fdf26e88fa41eb7d41c6efce322040c6fbbae3e7
26 changes: 13 additions & 13 deletions packages/shared/watchIgnorable/index.ts
AAC5
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ export function watchIgnorable<Immediate extends Readonly<boolean> = false>(
let stop: () => void

if (watchOptions.flush === 'sync') {
const ignore = shallowRef(false)
let ignore = false

// no op for flush: sync
ignorePrevAsyncUpdates = () => {}

ignoreUpdates = (updater: () => void) => {
// Call the updater function and count how many sync updates are performed,
// then add them to the ignore count
ignore.value = true
ignore = true
updater()
ignore.value = false
ignore = false
}

stop = watch(
source,
(...args) => {
if (!ignore.value)
if (!ignore)
filteredCb(...args)
},
watchOptions,
Expand All @@ -76,19 +76,19 @@ export function watchIgnorable<Immediate extends Readonly<boolean> = false>(
// are more sync triggers than the ignore count, the we now
// there are modifications in the source ref value that we
// need to commit
const ignoreCounter = shallowRef(0)
const syncCounter = shallowRef(0)
let ignoreCounter = 0
let syncCounter = 0

ignorePrevAsyncUpdates = () => {
ignoreCounter.value = syncCounter.value
ignoreCounter = syncCounter
}

// Sync watch to count modifications to the source
disposables.push(
watch(
source,
() => {
syncCounter.value++
syncCounter++
},
{ ...watchOptions, flush: 'sync' },
),
Expand All @@ -97,9 +97,9 @@ export function watchIgnorable<Immediate extends Readonly<boolean> = false>(
ignoreUpdates = (updater: () => void) => {
// Call the updater function and count how many sync updates are performed,
// then add them to the ignore count
const syncCounterPrev = syncCounter.value
const syncCounterPrev = syncCounter
updater()
ignoreCounter.value += syncCounter.value - syncCounterPrev
ignoreCounter += syncCounter - syncCounterPrev
}

disposables.push(
Expand All @@ -108,9 +108,9 @@ export function watchIgnorable<Immediate extends Readonly<boolean> = false>(
(...args) => {
// If a history operation was performed (ignoreCounter > 0) and there are
// no other changes to the source ref value afterwards, then ignore this commit
const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value
ignoreCounter.value = 0
syncCounter.value = 0
const ignore = ignoreCounter > 0 && ignoreCounter === syncCounter
ignoreCounter = 0
syncCounter = 0
if (ignore)
return

Expand Down
0