<commit_before>title: Instance Methods
type: api
order: 4
---

## Data

> You can observe data changes on a ViewModel. Note that all watch callbacks fire asynchronously. In addition, value changes are batched within an event loop. This means when a value changes multiple times within a single event loop, the callback will be fired only once with the latest value.

### vm.$watch( keypath, callback )

- **keypath** `String`
- **callback( newValue )** `Function`

Watch a keypath on the vm's data object for changes and call the callback with the new value.

### vm.$unwatch( keypath, [callback] )

- **keypath** `String`
- **callback** `Function` *optional*

Stop watching the given keypath. If a callback is given only that callback gets unwatched.

### vm.$get( keypath )

- **keypath** `String`

Retrieve a data value from the vm given a keypath. Non-existent paths always return `undefined`.
<commit_msg>$set doc update<commit_after>title: Instance Methods
type: api
order: 4
---

## Data

> You can observe data changes on a ViewModel. Note that all watch callbacks fire asynchronously. In addition, value changes are batched within an event loop. This means when a value changes multiple times within a single event loop, the callback will be fired only once with the latest value.

### vm.$watch( keypath, callback )

- **keypath** `String`
- **callback( newValue )** `Function`

Watch a keypath on the vm's data object for changes and call the callback with the new value.

### vm.$unwatch( keypath, [callback] )

- **keypath** `String`
- **callback** `Function` *optional*

Stop watching the given keypath. If a callback is given only that callback gets unwatched.

### vm.$get( keypath )

- **keypath** `String`

Retrieve a data value from the vm given a keypath. If the first segment of the path is not found on the current vm, it will recursively go upwards the parent chain until it reaches the root, so this can be useful for accessing a property that exist on the parent chain but with unknown distance. Non-existent paths always return `undefined`.

{'fraction_non_alphanumeric': 0.0899854862119013, 'fraction_numerical': 0.0009675858732462506, 'mean_word_length': 4.248730964467005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3078606', 'n_tokens_mistral': 578, 'n_tokens_neox': 548, 'n_words': 298}