Skip to content

Commit

Permalink
feat: pouchdb-hoodie-api@2.0.0
Browse files Browse the repository at this point in the history
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`)
  • Loading branch information
gr2m committed Mar 4, 2017
1 parent 5d00030 commit 852393e
Show file tree
Hide file tree
Showing 20 changed files with 13 additions and 471 deletions.
15 changes: 6 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ var EventEmitter = require('events').EventEmitter
var merge = require('lodash/merge')

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

function Store (dbName, options) {
Expand Down Expand Up @@ -40,7 +38,6 @@ function Store (dbName, options) {

var state = {
objectTypeById: {},
scopedApis: {},
db: db
}

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

var api = merge(
scoped.bind(null, state, storeApi),
{
db: storeApi.db,
add: storeApi.add,
Expand All @@ -66,12 +62,13 @@ function Store (dbName, options) {
removeAll: storeApi.removeAll,
on: storeApi.on,
one: storeApi.one,
off: storeApi.off
off: storeApi.off,
withIdPrefix: storeApi.withIdPrefix
},
{
push: syncWrapper.bind(syncApi, 'push'),
pull: syncWrapper.bind(syncApi, 'pull'),
sync: syncWrapper.bind(syncApi, 'sync'),
push: syncApi.push,
pull: syncApi.pull,
sync: syncApi.sync,
connect: syncApi.connect,
disconnect: syncApi.disconnect,
isConnected: syncApi.isConnected,
Expand All @@ -93,7 +90,7 @@ Store.defaults = function (defaultOpts) {

options = merge({}, defaultOpts, options)

return Store(dbName, options)
return new Store(dbName, options)
}

return CustomStore
Expand Down
12 changes: 5 additions & 7 deletions lib/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module.exports = reset
var merge = require('lodash/merge')

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

function reset (dbName, CustomPouchDB, state, api, clear, emitter, remoteBaseUrl, remote, options) {
if (options) {
Expand Down Expand Up @@ -34,7 +32,6 @@ function reset (dbName, CustomPouchDB, state, api, clear, emitter, remoteBaseUrl

merge(
api,
scoped.bind(null, state, storeApi),
{
db: storeApi.db,
add: storeApi.add,
Expand All @@ -48,12 +45,13 @@ function reset (dbName, CustomPouchDB, state, api, clear, emitter, remoteBaseUrl
removeAll: storeApi.removeAll,
on: storeApi.on,
one: storeApi.one,
off: storeApi.off
off: storeApi.off,
withIdPrefix: storeApi.storeApi
},
{
push: syncWrapper.bind(syncApi, 'push'),
pull: syncWrapper.bind(syncApi, 'pull'),
sync: syncWrapper.bind(syncApi, 'sync'),
push: syncApi.push,
pull: syncApi.pull,
sync: syncApi.sync,
connect: syncApi.connect,
disconnect: syncApi.disconnect,
isConnected: syncApi.isConnected
Expand Down
18 changes: 0 additions & 18 deletions lib/scoped/add.js

This file was deleted.

11 changes: 0 additions & 11 deletions lib/scoped/find-all.js

This file was deleted.

64 changes: 0 additions & 64 deletions lib/scoped/find-or-add.js

This file was deleted.

36 changes: 0 additions & 36 deletions lib/scoped/find.js

This file was deleted.

47 changes: 0 additions & 47 deletions lib/scoped/index.js

This file was deleted.

16 changes: 0 additions & 16 deletions lib/scoped/remove-all.js

This file was deleted.

15 changes: 0 additions & 15 deletions lib/scoped/remove.js

This file was deleted.

17 changes: 0 additions & 17 deletions lib/scoped/update-all.js

This file was deleted.

55 changes: 0 additions & 55 deletions lib/scoped/update-or-add.js

This file was deleted.

0 comments on commit 852393e

Please sign in to comment.