Any pointers on how to use tinybase in a webworker? #208
Replies: 2 comments
-
I believe this should be handled by the the chosen Persister's autoLoad functionality. Changes to the Tinybase store persisted in local storage in your example will be detected on the UI thread by storage event listeners registered by the Persister and from then will be propagated to queries (or store methods) that have Tinybase listeners registered. |
Beta Was this translation helpful? Give feedback.
-
That should work. I'm tempted to say that a more rigorous pattern would be to use a synchronizer so that if the UI and worker got out of sync, you'd get CRDT reconciliation. That would also allow you to have the worker syncing with a server while the frontend is syncing with the worker - they will all end up consistent, in theory! Checkout BroadcastChannelSynchronizer, created with createBroadcastChannelSynchronizer so that you can sync to the worker over a channel. ![]() ...but store1 and store2 are in UI & worker code respectively. Just make sure to share the channel name! That all said, I haven't got a template of this in action, so implementing this would be a small exercise for the reader. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
If we use tinybase in a web worker, what is the recommended way to sync the data to a Preact Context running on the main UI thread?
Beta Was this translation helpful? Give feedback.
All reactions