Skip to content

Commit

Permalink
docs: add the flush option for $watch (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
skirtles-code committed Oct 7, 2020
1 parent 998a71e commit a09c316
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/api/instance-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `{Object} options (optional)`
- `{boolean} deep`
- `{boolean} immediate`
- `{string} flush`

- **Returns:** `{Function} unwatch`

Expand Down Expand Up @@ -172,6 +173,24 @@
)
```
- **Option: flush**
The `flush` option allows for greater control over the timing of the callback. It can be set to `'pre'`, `'post'` or `'sync'`.
The default value is `'pre'`, which specifies that the callback should be invoked before rendering. This allows the callback to update other values before the template runs.
The value `'post'` can be used to defer the callback until after rendering. This should be used if the callback needs access to the updated DOM or child components via `$refs`.
If `flush` is set to `'sync'`, the callback will be called synchronously, as soon as the value changes.
For both `'pre'` and `'post'`, the callback is buffered using a queue. The callback will only be added to the queue once, even if the watched value changes multiple times. The interim values will be skipped and won't be passed to the callback.

Buffering the callback not only improves performance but also helps to ensure data consistency. The watchers won't be triggered until the code performing the data updates has finished.
`'sync'` watchers should be used sparingly, as they don't have these benefits.

For more information about `flush` see [Effect Flush Timing](../guide/reactivity-computed-watchers.html#effect-flush-timing).

- **See also:** [Watchers](../guide/computed.html#watchers)

## $emit
Expand Down
2 changes: 1 addition & 1 deletion src/api/options-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@

- **Details:**

An object where keys are expressions to watch and values are the corresponding callbacks. The value can also be a string of a method name, or an Object that contains additional options. The component instance will call `$watch()` for each entry in the object at instantiation.
An object where keys are expressions to watch and values are the corresponding callbacks. The value can also be a string of a method name, or an Object that contains additional options. The component instance will call `$watch()` for each entry in the object at instantiation. See [$watch](instance-methods.html#watch) for more information about the `deep`, `immediate` and `flush` options.

- **Example:**

Expand Down

0 comments on commit a09c316

Please sign in to comment.