hoodiehq/wip-hoodie-store-on-pouchdb — pull request #26 by gr2m (2014-12-28 17:24:10+00:00)
Title: Implement events

- [x] hoodie.store.on('add', function(object, options) {})
- [ ] hoodie.store.on('update', function(object, options) {})
- [ ] hoodie.store.on('remove', function(object, options) {})
- [ ] hoodie.store.on('change', function(eventName, object, options) {})
- [ ] hoodie.store.on('sync', function(object) {}) #27
- [ ] hoodie.store.on('clear', function() {}) #28

```js
hoodie.store.on('add', function(object, options) {
console.log(object.name, 'added');
})
hoodie.store.on('update', function(object, options) {
console.log(object.name, 'updated');
})
hoodie.store.on('remove', function(object, options) {
console.log(object.name, 'removed');
})
hoodie.store.on('change', function(eventName, object, options) {
console.log(object.name, 'changed');
})

hoodie.store.add({id: '123', name: 'Finn'})
// < Finn added
// < Finn changed

hoodie.store.update(123, {name: 'Marceline'})
// < Marceline updated
// < Marceline changed

hoodie.store.remove(123)
// < Marceline removed
// < Marceline changed

hoodie.store.add({name: 'Jake'},{name: 'BMO'})
// < Jake added
// < Jake changed
// < BMO added
// < BMO changed

hoodie.store.removeAll()
// < Jake removed
// < Jake changed
// < BMO removed
// < BMO changed
```

Changes can also come from remote trough sync.

```
hoodie.store.connect()
hoodie.store.on('change', function(eventName, object, options) {
if (options.remote) {
console.log('new change from remote!');
}
})

hoodie.store.add({})
//
```

now let's imagine, that in the CouchDB database an object got deleted, you'd see in your console:
> new change from remote!