JSPM

cycle-pouchdb-most-driver

0.0.5
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q31871F
  • License MIT

A PouchDB driver that returns easy streams to be used with Cycle's most-run

Package Exports

  • cycle-pouchdb-most-driver

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cycle-pouchdb-most-driver) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

This is a driver for all your pure-most Cycle apps (think Motorcycle) that speak with PouchDB.

It returns streams from .get, .query and .changes methods for easy read access to PouchDB data, and accepts .put and .remove operations for write.

Install

npm install --save cycle-pouchdb-most-driver

Use

import most from 'most'
import PouchDB from 'pouchdb-browser'
import {makeDOMDriver} from '@motorcycle/dom'
import {makePouchDBDriver} from 'cycle-pouchdb-most-driver'
import Cycle from '@cycle/most-run'

Cycle.run(app, {
  DOM: makeDOMDriver('#container'),
  POUCHDB: makePouchDBDriver(PouchDB, 'my-db-name')
})

function app ({DOM, POUCHDB}) {
  let vtree$ = POUCHDB
    .query('my-ddoc/items-by-time', {descending: true, startkey: [{}], endkey: [null], include_docs: true})
    .map(res => res.rows.map(r => r.doc))
    .map(items =>
      h('ul', items.map(item =>
        h('li', {props: {id: item._id}}, item.name)
      ))
    )

  return {
    DOM: vtree$,
    POUCHDB: most.from([
      POUCHDB.put({
        '_id': '_design/my-ddoc',
        'views': {
          'items-by-time': {
            'map': `
              function (doc) {
                if (doc.type == 'item') {
                  emit([doc.year, doc.month, doc.day, doc.time], doc.value)
                }
              }
            `
          }
        }
      }),
      POUCHDB.put({_id: 'xyz', name: 'lalala', year: 2018, month: 2, day: 21, time: '14:44:23'})
      POUCHDB.put({_id: 'uyt', name: 'lololo', year: 2018, month: 2, day: 22, time: '10:01:36'})
    ])
  }
}