1.4.5 • Published 9 years ago

pouchdb-event-store v1.4.5

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

pouchdb-event-store

mimimal eventStore on top of pouchdb

bitHound Overall Score npm Package npm Package travis-ci.org js-standard-style license

Usage

npm i pouchdb-event-store
const PouchDB = require('pouchdb') // or pouchdb-node / pouchdb-browser / pouchdb-react-native
const pouchdbEventStore = require('pouchdb-event-store')

let lastId = 0
const options = {
  pouchdb: new PouchDB('events'),
  idGenerator: {
    next () { return new Promise((resolve, reject) => { resolve(lastId++) }) }
  },
  viewModels: [
    {
      pouchdb: new PouchDB('viewModel'),
      reducer (state, event) {
        if (!state.items) state.items = []
        state.items.push(event)
        return state
      }
    }
  ]
}

const eventStoreFactory = pouchdbEventStore(options)
eventStoreFactory.create()
  .then((eventStore) => eventStore.add({type: 'CREATE'}, 123))
  .then((result) => {
    console.log(result)
  })
  .catch((error) => console.error(error))

eventStoreFactory.get('1')
  .then((eventStore) => {
    console.log(eventStore.getEvents())
  })
  .catch((error) => console.error(error))

// or callback style
eventStoreFactory(options).create((error, eventStore) => {
  if (error) return console.error(error)
  eventStore.add({type: 'CREATE'}, 123, (error, result) => {
    if (error) return console.error(error)
    console.log(result)
  })
})

eventStoreFactory.get('2', (error, eventStore) => {
  if (error) return console.error(error)
  console.log(eventStore.getEvents())
})

Twitter URL GitHub stars

1.4.5

9 years ago

1.4.4

9 years ago

1.4.3

9 years ago

1.4.2

9 years ago

1.4.1

9 years ago

1.4.0

9 years ago

1.3.5

9 years ago

1.3.4

9 years ago

1.3.3

9 years ago

1.3.2

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.6

9 years ago

1.2.5

9 years ago

1.2.4

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago