Testingpouchdb change handler
This commit is contained in:
1 parent
063bee4e28
commit
6465a371cb
3 files changed
+40
-1
No files matched your search
@@ -0,0 +1,6 @@
|
||||
|
||||
const changeHandler = (change: any) => {
|
||||
console.log({caller: 'ChangeHandler', change});
|
||||
}
|
||||
|
||||
export default changeHandler;
|
||||
@@ -2,6 +2,7 @@ import _ from 'lodash';
|
||||
import PouchDB from 'pouchdb';
|
||||
import PouchDBFind from 'pouchdb-find';
|
||||
import uri from '../lib/ids';
|
||||
import changeHandler from './change-handler';
|
||||
|
||||
PouchDB.plugin(PouchDBFind);
|
||||
|
||||
@@ -19,6 +20,8 @@ declare global {
|
||||
}
|
||||
|
||||
export const initDb = async (params: any) => {
|
||||
console.log({ caller: 'initDb' });
|
||||
|
||||
if (globalThis.db === undefined) {
|
||||
globalThis.db = new PouchDB('dyomedea', {
|
||||
auto_compaction: false,
|
||||
@@ -93,6 +96,26 @@ export const initDb = async (params: any) => {
|
||||
|
||||
globalThis.dbReady = true;
|
||||
|
||||
console.log({ caller: 'initDb / before db.changes' });
|
||||
|
||||
const changes = db
|
||||
.changes({ since: 'now', live: true, include_docs: true })
|
||||
.on('change', changeHandler)
|
||||
// .on('change', (info: any) => {
|
||||
// console.log({ caller: 'changes / change', info });
|
||||
// changeHandler(info);
|
||||
// })
|
||||
.on('complete', (info: any) => {
|
||||
console.log({ caller: 'changes / complete', info });
|
||||
})
|
||||
.on('error', (error: any) => {
|
||||
console.log({ caller: 'changes / complete', error });
|
||||
});
|
||||
|
||||
console.log({ caller: 'initDb / back from db.changes', changes });
|
||||
|
||||
// changes.cancel();
|
||||
|
||||
/* const indexes = await db.getIndexes();
|
||||
console.log(`indexes: ${JSON.stringify(indexes)}`);
|
||||
|
||||
|
||||
Reference in new issue
Block a user