Skip to content

Commit 852393e

Browse files
committed
BREAKING CHANGE: - Before, change events (incl. add, update, remove) have only been triggered when using the custom APIs like `.add()` or `.update()`. Now they get always triggered, including for changes replicated into the database. hoodiehq/pouchdb-hoodie-api@1958c42 - the order of when the methods’ promises resolve and the events get triggered cannot be guaranteed as we rely on PouchDB’s .changes(). We would love to enforce promises to resolve after changes get emitted, but the required complexity to do that is not worth it. - separate methods like `require(pouchdb-hoodie-api/add)` can no longer be required directly The reason for that is that all the methods now also accept a `prefix` argument which by default is null. That way we don’t need to implement each method twice, once for `store.add`, and once for `store.withIdPrefix(test/).add` - We no longer map PouchDB’s `._id` property to `.id`, instead we pass trough docs from PouchDB 1:1. Also the timestamps are now all namespaced with `.hoodie` (`doc.createdAt` becomes `doc.hoodie.createdAt`)
1 parent 5d00030 commit 852393e

20 files changed

+13
-471
lines changed

index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ var EventEmitter = require('events').EventEmitter
55
var merge = require('lodash/merge')
66

77
var subscribeToSyncEvents = require('./lib/subscribe-to-sync-events')
8-
var syncWrapper = require('./lib/sync-wrapper')
9-
var scoped = require('./lib/scoped/')
108
var isPersistent = require('./lib/is-persistent')
119

1210
function Store (dbName, options) {
@@ -40,7 +38,6 @@ function Store (dbName, options) {
4038

4139
var state = {
4240
objectTypeById: {},
43-
scopedApis: {},
4441
db: db
4542
}
4643

@@ -52,7 +49,6 @@ function Store (dbName, options) {
5249
})
5350

5451
var api = merge(
55-
scoped.bind(null, state, storeApi),
5652
{
5753
db: storeApi.db,
5854
add: storeApi.add,
@@ -66,12 +62,13 @@ function Store (dbName, options) {
6662
removeAll: storeApi.removeAll,
6763
on: storeApi.on,
6864
one: storeApi.one,
69-
off: storeApi.off
65+
off: storeApi.off,
66+
withIdPrefix: storeApi.withIdPrefix
7067
},
7168
{
72-
push: syncWrapper.bind(syncApi, 'push'),
73-
pull: syncWrapper.bind(syncApi, 'pull'),
74-
sync: syncWrapper.bind(syncApi, 'sync'),
69+
push: syncApi.push,
70+
pull: syncApi.pull,
71+
sync: syncApi.sync,
7572
connect: syncApi.connect,
7673
disconnect: syncApi.disconnect,
7774
isConnected: syncApi.isConnected,
@@ -93,7 +90,7 @@ Store.defaults = function (defaultOpts) {
9390

9491
options = merge({}, defaultOpts, options)
9592

96-
return Store(dbName, options)
93+
return new Store(dbName, options)
9794
}
9895

9996
return CustomStore

lib/reset.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ module.exports = reset
33
var merge = require('lodash/merge')
44

55
var subscribeToSyncEvents = require('./subscribe-to-sync-events')
6-
var syncWrapper = require('./sync-wrapper')
7-
var scoped = require('./scoped/')
86

97
function reset (dbName, CustomPouchDB, state, api, clear, emitter, remoteBaseUrl, remote, options) {
108
if (options) {
@@ -34,7 +32,6 @@ function reset (dbName, CustomPouchDB, state, api, clear, emitter, remoteBaseUrl
3432

3533
merge(
3634
api,
37-
scoped.bind(null, state, storeApi),
3835
{
3936
db: storeApi.db,
4037
add: storeApi.add,
@@ -48,12 +45,13 @@ function reset (dbName, CustomPouchDB, state, api, clear, emitter, remoteBaseUrl
4845
removeAll: storeApi.removeAll,
4946
on: storeApi.on,
5047
one: storeApi.one,
51-
off: storeApi.off
48+
off: storeApi.off,
49+
withIdPrefix: storeApi.storeApi
5250
},
5351
{
54-
push: syncWrapper.bind(syncApi, 'push'),
55-
pull: syncWrapper.bind(syncApi, 'pull'),
56-
sync: syncWrapper.bind(syncApi, 'sync'),
52+
push: syncApi.push,
53+
pull: syncApi.pull,
54+
sync: syncApi.sync,
5755
connect: syncApi.connect,
5856
disconnect: syncApi.disconnect,
5957
isConnected: syncApi.isConnected

lib/scoped/add.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/scoped/find-all.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/scoped/find-or-add.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

lib/scoped/find.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

lib/scoped/index.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

lib/scoped/remove-all.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

lib/scoped/remove.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/scoped/update-all.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)