-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synchronizes database events between multiple clients #66
Conversation
7c906ca
to
60813bc
Compare
60813bc
to
f225af7
Compare
927cc85
to
b05a39f
Compare
private generateId() { | ||
const { stack } = new Error() | ||
const callFrame = stack?.split('\n')[4] | ||
const salt = `${callOrder}-${callFrame?.trim()}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using an invocation order and database location to identify a single database instance.
The order of factory()
calls is unlikely to change on runtime. Two first-created databases across clients aren't necessarily the same instances, as each client may load a different module, while the same BroadcastChannel
controls the entire host. To account for that, I'm adding a module location to the hash salt.
Two database instances on multiple pages are equal if:
- They were called in the same order.
- They were created in the same module.
Ignoring unrelated eventsIt's possible to have multiple
Unfortunately, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks very good :) nice 💯
GitHub
Changes
factory()
is called. Factory creates an internalDatabase
instance).Motivation
Client-side sync allows the database to feel like an actual external database you're working with, as its updates you provision in one tab are synced with the other tabs as if they are requesting the same database. In reality, each tab has its own runtime and creates its own database from a clean slate.
Roadmap
db
instances sync their updates independently.