From 265c248df36c09f63fcfb559b766a2eb79a79617 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Tue, 14 Mar 2023 20:21:27 -0700 Subject: [PATCH] Move resource listener registration to run in all tabs, not just the leader tab. --- .../contentcuration/frontend/shared/data/index.js | 8 ++++++++ .../contentcuration/frontend/shared/data/serverSync.js | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contentcuration/contentcuration/frontend/shared/data/index.js b/contentcuration/contentcuration/frontend/shared/data/index.js index 017fcfed46..70588e4079 100644 --- a/contentcuration/contentcuration/frontend/shared/data/index.js +++ b/contentcuration/contentcuration/frontend/shared/data/index.js @@ -61,10 +61,18 @@ function runElection() { }; } +function applyResourceListener(change) { + const resource = INDEXEDDB_RESOURCES[change.table]; + if (resource && resource.listeners && resource.listeners[change.type]) { + resource.listeners[change.type](change); + } +} + export async function initializeDB() { try { setupSchema(); await db.open(); + db.on('changes', changes => changes.map(applyResourceListener)); await runElection(); } catch (e) { Sentry.captureException(e); diff --git a/contentcuration/contentcuration/frontend/shared/data/serverSync.js b/contentcuration/contentcuration/frontend/shared/data/serverSync.js index 68b0e7f02b..5ad46e0ba7 100644 --- a/contentcuration/contentcuration/frontend/shared/data/serverSync.js +++ b/contentcuration/contentcuration/frontend/shared/data/serverSync.js @@ -69,13 +69,6 @@ function isSyncableChange(change) { ); } -function applyResourceListener(change) { - const resource = INDEXEDDB_RESOURCES[change.table]; - if (resource && resource.listeners && resource.listeners[change.type]) { - resource.listeners[change.type](change); - } -} - /** * Reduces a change to only the fields that are needed for sending it to the backend * @@ -338,7 +331,6 @@ if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') { } async function handleChanges(changes) { - changes.map(applyResourceListener); const syncableChanges = changes.filter(isSyncableChange); // Here we are handling changes triggered by Dexie Observable // this is listening to all of our IndexedDB tables, both for resources