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:
Add ICollectionRxOptions['pagination'] which represents pagination options accepted by allDocs.
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.
Pass Collection._allDocsSubject to filter, then subscribe it to Filter.filter().
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.
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:
ICollectionRxOptions['pagination']
which represents pagination options accepted by allDocs.Collection.all()
toCollection.allDocs(options)
and replaceColletion.loadDocs
source withCollection.allDocs(options)
, we still need to call loadDocs with firstICollectionRxOptions['pagination']
value or startsWith{}
at first.Collection._allDocsSubject
to filter, then subscribe it to Filter.filter().ICollectionRxOptions['pagination']
and callCollection._store.setDocs(res)
to update store, and then the filter.That's it.
Maybe some supported pagination related keys from allDocs options: