-
-
Notifications
You must be signed in to change notification settings - Fork 116
Description
Describe the bug
Unexpected Data Sync Across Stores and Empty Persister Path in TinyBase
Hi there!
First off, let me say this is a fantastic library—thank you for the effort that’s gone into it!
I’ve been playing around with tinybase
and hit a couple of snags. It’s entirely possible I’m missing something obvious, but I wanted to reach out to clarify. Here’s my setup:
Server Code
import { WebSocketServer } from "ws";
import { createWsServer } from "tinybase/synchronizers/synchronizer-ws-server";
const wsserver = new WebSocketServer({ port: 8040 });
const server = createWsServer(wsserver, (pathid) => {
console.log("pathid ", pathid);
});
setInterval(() => {
console.log(server.getStats());
console.log(server.getPathIds());
}, 1000);
Client 1
This client creates a mergeable store with ID store1
and incrementally sets the count
value.
import { createMergeableStore } from "tinybase";
import { createWsSynchronizer } from "tinybase/synchronizers/synchronizer-ws-client";
import ReconnectingWebSocket from "reconnecting-websocket";
const store = createMergeableStore("store1");
const synchronizer = await createWsSynchronizer(
store,
new ReconnectingWebSocket("ws://localhost:8040")
);
async function main() {
let i = 0;
await synchronizer.startSync();
setInterval(() => {
console.log("setting count", i);
store.setValues({ count: i });
console.log(store.getValues());
i++;
}, 1000);
}
main();
Client 2
This one creates a mergeable store with ID store1
as well and just prints values.
import { createMergeableStore } from "tinybase";
import { createWsSynchronizer } from "tinybase/synchronizers/synchronizer-ws-client";
import ReconnectingWebSocket from "reconnecting-websocket";
const store = createMergeableStore("store1");
const synchronizer = await createWsSynchronizer(
store,
new ReconnectingWebSocket("ws://localhost:8040")
);
async function main() {
await synchronizer.startSync();
setInterval(() => {
console.log("get client2 store1", store.getValues());
}, 1000);
}
main();
Client 3
This client creates a mergeable store with ID store2
and just prints values.
import { createMergeableStore } from "tinybase";
import { createWsSynchronizer } from "tinybase/synchronizers/synchronizer-ws-client";
import ReconnectingWebSocket from "reconnecting-websocket";
const store = createMergeableStore("store2");
const synchronizer = await createWsSynchronizer(
store,
new ReconnectingWebSocket("ws://localhost:8040")
);
async function main() {
await synchronizer.startSync();
setInterval(() => {
console.log("get client3 store2", store.getValues());
}, 1000);
}
main();
The Issues
- All clients seem to be receiving data for
store1
, even thoughclient3
is usingstore2
. - The server's
createPersisterForPath
function always returns an empty string.
Any insight into what might be causing these issues would be greatly appreciated. Let me know if I’ve missed something, or if you’d like me to provide more details or tweak my setup.
Thanks again for the great library and for taking the time to look into this!
Cheers
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
No response
Expected behavior
No response
Screenshots or Videos
No response
Platform
- OS: [Linux]
Additional context
No response