Signals are very handy in web workers !
This commit is contained in:
parent
89689c5ed6
commit
534ec32312
|
@ -2,7 +2,7 @@ import { createEffect, createRoot, createSignal, Signal } from 'solid-js';
|
|||
import PouchDB from 'pouchdb';
|
||||
import indexeddb from 'pouchdb-adapter-indexeddb';
|
||||
|
||||
import { sleep } from '../lib/async-wait';
|
||||
import { sleep, until } from '../lib/async-wait';
|
||||
import { openDatabases } from './open';
|
||||
import { toHex } from '../lib/to-hex';
|
||||
import { isEqual } from 'lodash';
|
||||
|
@ -17,11 +17,11 @@ declare global {
|
|||
var sync: any;
|
||||
}
|
||||
|
||||
const [state, setState] = createSignal({});
|
||||
const [state, setState] = createSignal<any>({});
|
||||
export { state };
|
||||
|
||||
export const watchDbLegacy = async () => {
|
||||
createRoot((dispose) => {
|
||||
createRoot(async (dispose) => {
|
||||
console.log({ caller: 'watchDbLegacy' });
|
||||
|
||||
db = globalThis.db;
|
||||
|
@ -61,14 +61,15 @@ export const watchDbLegacy = async () => {
|
|||
});
|
||||
|
||||
createEffect(() => {
|
||||
const newState = { ...state(), sync: syncState() };
|
||||
if (!isEqual(newState, state())) {
|
||||
setState({
|
||||
const newState = {
|
||||
...state(),
|
||||
dbName: status()?.dbInfo?.db_name,
|
||||
localUpdateSeq: status()?.dbInfo?.update_seq,
|
||||
remoteUrl: status()?.remoteDbInfo?.host,
|
||||
sync: syncState(),
|
||||
});
|
||||
};
|
||||
if (!isEqual(newState, state())) {
|
||||
setState(newState);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -157,6 +158,14 @@ export const watchDbLegacy = async () => {
|
|||
};
|
||||
});
|
||||
|
||||
await until(
|
||||
() =>
|
||||
state()?.sync?.paused &&
|
||||
state()?.sync?.lastSeq >= state()?.localUpdateSeq,
|
||||
1000
|
||||
);
|
||||
|
||||
console.log({ caller: 'watchDbLegacy / ready to purge after sync ' });
|
||||
// const iDb = (await openIDb('_pouch__dyomedea_')) as IDBDatabase;
|
||||
|
||||
// const bySequence = iDb.transaction('docs', 'readonly');
|
||||
|
|
Loading…
Reference in New Issue