Skip to content

Commit 5624f3a

Browse files
committed
Merge pull request #28 from BigBlueHat/patch-2
added note about $data and mutation object
2 parents 99590c7 + 5d30538 commit 5624f3a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

source/api/instance-methods.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,23 @@ order: 4
1010
### vm.$watch( keypath, callback )
1111

1212
- **keypath** `String`
13-
- **callback( newValue )** `Function`
13+
- **callback( newValue, [mutation])** `Function`
1414

15-
Watch a keypath on the vm's data object for changes and call the callback with the new value.
15+
Watch a keypath on the vm's data object (or the `$data` object itself) for changes and call the callback with the new value.
16+
17+
A second `mutation` object is also available and is useful when watching arrarys:
18+
19+
```javascript
20+
this.$watch('list', function (value, mutation) {
21+
if (mutation) {
22+
mutation.method // e.g. 'push'
23+
mutation.args // raw arguments to the mutation method
24+
mutation.result // return value
25+
mutation.inserted // new, inserted elements
26+
mutation.removed // removed elements
27+
}
28+
})
29+
```
1630

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

@@ -110,4 +124,4 @@ Remove the vm's `$el` from the DOM.
110124

111125
### vm.$destroy()
112126

113-
Completely destroy a vm. Clean up its connections with other existing vms, unbind all its directives and remove its `$el` from the DOM. Also, all `$on` and `$watch` listeners will be automatically removed.
127+
Completely destroy a vm. Clean up its connections with other existing vms, unbind all its directives and remove its `$el` from the DOM. Also, all `$on` and `$watch` listeners will be automatically removed.

0 commit comments

Comments
 (0)