Git Product home page Git Product logo

rxpouch's Introduction

Under heavy development

You can use it, but stuff might still changes quickly, until we are at version 1.0.0

Docs

Read the official docs or look in the example directory.

Introduction

RxPouch is RxJS powered PouchDB, with some additional features, but still tried to provide all the same base functionallities. You can almost everywhere consult the PouchDB Docs for further information.

Installation

npm install rx-pouch --save
npm install rxjs --save

Difference to RxDB

Well a lot of credits goes to RxDB, since we borrowed a lot from them. In RxDB every collection creates a new database, which is in most use-cases perfectly fine. For my use-case it wasn't.

  • RxDB uses multiply databases, RxPouch uses document keys with the prefix <collection>- and adds to each document a property type: '<collection>'
  • RxDB has their own API
  • RxPouch tried to follow the official PouchDB API as close as possible, but also added some sugar.
  • RxPouch got less features (Leader Election, Schema, Population etc..)
  • RxPouch has a different filter / sorting system

Example usage

let RxPouch = require("rx-pouch");
let pouchLevelDB = require("pouchdb-adapter-leveldb");

process.on('unhandledRejection', (reason, promise) => {
    console.log('Unhandled Rejection at:', reason.stack || reason)
});


// add db adapter for nodejs
RxPouch.plugin(pouchLevelDB);

// create database
let db = new RxPouch('myDB');

// start listening for changes, enables all observers
let changes = db.changes();
changes.change$.subscribe(next => {
    console.log('change', next);
});

// create collection
let pokemons = db.collection('pokemon');

// listen for changes
pokemons.insert$.subscribe(next => {
    console.log('may display an notification that there is a new pokemon');
});

pokemons.remove$.subscribe(next => {
    console.log('may navigate away, from current pokemon page');
});

pokemons.docs$.subscribe(next => {
    console.log('may display an up to date list of all stored pokemons');
});

// create a doc
let pika = {
    _id: 'pikachu', // will result in pokemon-pikachu
    type: 'pokemon', // not needed, will be set anyway
    name: 'Pikachu',
    power: '120',
    element: 'power'
};

// insert data
pokemons.create(pika);

rxpouch's People

Contributors

pablomaurer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rxpouch's Issues

create tests

Everything is ready to start writing tests using:

  • ts-jest
  • jest

pouchdb and webpack

you need do import like pouchdb/dist/pouchdb else webpack goes for the files in lib, where it will somewhere include stuff not meant for the browser?

also have to switch back to custom bundling.. But then user using webpack will still have those pouchdb issues.

So best try to fix it in pouchdb.

Support `allDocs(options)` or maybe `ICollectionRxOptions['pagination']`?

RxPouch/src/Collection.ts

Lines 179 to 190 in 31f412a

public async all() {
let endkey = this._docType + '-\uffff';
if (this._observableOptions.user) {
let user = await this._observableOptions.user.pipe(first(user => user as any)).toPromise();
endkey = this._docType + '-' + user + '\uffff'
}
let res = await this._pouchdb.allDocs({
startkey: this._docType,
endkey: endkey,
include_docs: true
});

RxPouch/src/Filter.ts

Lines 27 to 29 in 31f412a

public _init() {
this._docsSubject.next(this._getAllDocs());

It looks like that I have to load all documents with collection type into store & filter, it's a bit horrible!
May we can add such an count() method.
Besides that, I want to reserve the pagination feature.

I find out a simple but tricky solution:

  1. Add ICollectionRxOptions['pagination'] which represents pagination options accepted by allDocs.
  2. Copy & Paste Collection.all() to Collection.allDocs(options) and replace Colletion.loadDocs source with Collection.allDocs(options), we still need to call loadDocs with first ICollectionRxOptions['pagination'] value or startsWith {} at first.
  3. Pass Collection._allDocsSubject to filter, then subscribe it to Filter.filter().
  4. Subscribe to ICollectionRxOptions['pagination'] and call Collection._store.setDocs(res) to update store, and then the filter.

That's it.


Maybe some supported pagination related keys from allDocs options:

  • options.startkey & options.endkey: Get documents with IDs in a certain range (inclusive/inclusive).
  • options.inclusive_end: Include documents having an ID equal to the given options.endkey. Default: true.
  • options.limit: Maximum number of documents to return.
  • options.skip: Number of docs to skip before returning (warning: poor performance on IndexedDB/LevelDB!).
  • options.descending: Reverse the order of the output documents. Note that the order of startkey and endkey is reversed when descending:true.

check all destroys

  • are all destroy's cleaning everything up
  • everything got unsubscribed
  • called destroy on all created sub classes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.