Skip to content

docs(core): doc supplement #4899

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

Closed
wants to merge 3 commits into from
Closed
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
Prev Previous commit
Next Next commit
docs(useRefHistory): doc completion
  • Loading branch information
pkc918 committed Jul 30, 2025
commit ed530be769a2d51aa737aa29e0a98fe9b8c41969
16 changes: 16 additions & 0 deletions packages/core/useRefHistory/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ console.log(counter.value) // 0
When working with objects or arrays, since changing their attributes does not change the reference, it will not trigger the committing. To track attribute changes, you would need to pass `deep: true`. It will create clones for each history record.

```ts
import { useRefHistory } from '@vueuse/core'
import { nextTick, ref } from 'vue'

const state = ref({
foo: 1,
bar: 'bar',
Expand Down Expand Up @@ -112,6 +115,8 @@ const refHistory = useRefHistory(target, {
We will keep all the history by default (unlimited) until you explicitly clear them up, you can set the maximal amount of history to be kept by `capacity` options.

```ts
import { useRefHistory } from '@vueuse/core'

const refHistory = useRefHistory(target, {
capacity: 15, // limit to 15 history records
})
Expand All @@ -126,6 +131,8 @@ From [Vue's documentation](https://vuejs.org/guide/essentials/watchers.html#call
In the same way as `watch`, you can modify the flush timing using the `flush` option.

```ts
import { useRefHistory } from '@vueuse/core'

const refHistory = useRefHistory(target, {
flush: 'sync', // options 'pre' (default), 'post' and 'sync'
})
Expand All @@ -134,6 +141,9 @@ const refHistory = useRefHistory(target, {
The default is `'pre'`, to align this composable with the default for Vue's watchers. This also helps to avoid common issues, like several history points generated as part of a multi-step update to a ref value that can break invariants of the app state. You can use `commit()` in case you need to create multiple history points in the same "tick"

```ts
import { useRefHistory } from '@vueuse/core'
import { shallowRef } from 'vue'

const r = shallowRef(0)
const { history, commit } = useRefHistory(r)

Expand All @@ -154,6 +164,9 @@ console.log(history.value)
On the other hand, when using flush `'sync'`, you can use `batch(fn)` to generate a single history point for several sync operations

```ts
import { useRefHistory } from '@vueuse/core'
import { ref } from 'vue'

const r = ref({ names: [], version: 1 })
const { history, batch } = useRefHistory(r, { flush: 'sync' })

Expand All @@ -172,6 +185,9 @@ console.log(history.value)
If `{ flush: 'sync', deep: true }` is used, `batch` is also useful when doing a mutable `splice` in an array. `splice` can generate up to three atomic operations that will be pushed to the ref history.

```ts
import { useRefHistory } from '@vueuse/core'
import { ref } from 'vue'

const arr = ref([1, 2, 3])
const { history, batch } = useRefHistory(arr, { deep: true, flush: 'sync' })

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy