hoodiehq / pouchdb-hoodie-api

:dog: Hoodie-like API for PouchDB
https://hoodiehq.github.io/pouchdb-hoodie-api
Apache License 2.0
44 stars 11 forks source link

add events #31

Closed gr2m closed 9 years ago

gr2m commented 9 years ago
var db = new PouchDB('dbname')
var api = db.hoodieApi()

api.on('add', function(object, options) {})
api.on('update', function(object, options) {})
api.on('remove', function(object, options) {})
api.on('change', function(eventName, object, options) {})

api.one('add', function(object, options) {})
api.off('add', handler)

Events should be implemented using EventEmitter. See implementation / tests in https://github.com/hoodiehq/wip-hoodie-store-on-pouchdb

PouchDB.plugin({
  add: require('pouchdb-hoodie-api/add')
})
gr2m commented 9 years ago

@patriciagarcia could you add a test, in which a doc gets created in the db before we initiate the api, to make sure that no change event gets triggered for it?

patriciagarcia commented 9 years ago

@gr2m, before we initiate the API or before we start listening to events?

gr2m commented 9 years ago

excellent good question :) Before listening to events makes sense, it will cover the "before we initiate the API" part, too

patriciagarcia commented 9 years ago

there is one here https://github.com/hoodiehq/pouchdb-hoodie-api/commit/993c1a9ec880a82b4d29eca52fb02dac851eec40 :)

gr2m commented 9 years ago

closed via https://github.com/hoodiehq/pouchdb-hoodie-api/pull/34