pablomaurer / RxPouch

supercharged PouchDB with RxJS
https://mnewmedia.github.io/RxPouch/
6 stars 0 forks source link

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

Open msyfls123 opened 1 year ago

msyfls123 commented 1 year ago

https://github.com/pablomaurer/RxPouch/blob/31f412a2ec4b8727b6977ef4d39afeee4c00ab8b/src/Collection.ts#L179-L190 https://github.com/pablomaurer/RxPouch/blob/31f412a2ec4b8727b6977ef4d39afeee4c00ab8b/src/Filter.ts#L27-L29

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:

pablomaurer commented 1 year ago

This project ist not really maintained anymore =) But feel free to create a PR or the project ^^

Or look at https://github.com/pubkey/rxdb maybe they got you covered..