Dexie 实时查询和 Service Worker

Dexie Live Query and Service Worker

我想在 service worker 中使用 Dexie 来同步我的数据。 我也想在 React 前端使用 useLiveQuery 钩子。

如果服务工作者线程中写入新数据,Dexie 会自动更新查询吗?

如果您的 Service worker 将数据写入数据库,React 前端将立即收到通知并进行相应更新。通信通过 BroadcastChannel 进行。如果使用缺少 BroadcastChannel 支持的遗留 Safari 浏览器,dexie 有一个回退,以便在 service worker 中完成的突变将使用 postMessage() 进行通信。这一切都由dexie自己处理。