forked from hoodiehq/pouchdb-hoodie-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 1.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict'
var exports = module.exports = { hoodieApi: hoodieApi }
var EventEmitter = require('events').EventEmitter
var eventify = require('./helpers/eventify')
function hoodieApi (options) {
var state = {
emitter: options && options.emitter || new EventEmitter()
}
return {
db: this,
add: eventify(this, state, require('./add')),
find: require('./find').bind(this),
findAll: require('./find-all').bind(this),
findOrAdd: require('./lib/find-or-add-with-events').bind(this, state),
update: eventify(this, state, require('./update')),
updateOrAdd: eventify(this, state, require('./update-or-add')),
updateAll: eventify(this, state, require('./update-all')),
remove: eventify(this, state, require('./remove'), 'remove'),
removeAll: eventify(this, state, require('./remove-all'), 'remove'),
on: require('./lib/on').bind(this, state),
one: require('./lib/one').bind(this, state),
off: require('./lib/off').bind(this, state),
clear: require('./clear').bind(this, state)
}
}
/* istanbul ignore next */
if (typeof window !== 'undefined' && window.PouchDB) {
window.PouchDB.plugin(exports)
}