Skip to content

added note about $data and mutation object #28

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 1 commit into from
Jul 9, 2014
Merged
Changes from all commits
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
20 changes: 17 additions & 3 deletions source/api/instance-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@ order: 4
### vm.$watch( keypath, callback )

- **keypath** `String`
- **callback( newValue )** `Function`
- **callback( newValue, [mutation])** `Function`

Watch a keypath on the vm's data object for changes and call the callback with the new value.
Watch a keypath on the vm's data object (or the `$data` object itself) for changes and call the callback with the new value.

A second `mutation` object is also available and is useful when watching arrarys:

```javascript
this.$watch('list', function (value, mutation) {
if (mutation) {
mutation.method // e.g. 'push'
mutation.args // raw arguments to the mutation method
mutation.result // return value
mutation.inserted // new, inserted elements
mutation.removed // removed elements
}
})
```

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

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

### vm.$destroy()

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.
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.