Skip to content

Commit

Permalink
Temporarily add unload event code to detach user when close/refresh tab
Browse files Browse the repository at this point in the history
  • Loading branch information
JOOHOJANG committed Sep 10, 2024
1 parent 13f528b commit 0c6a7db
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions examples/vanilla-codemirror6/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ async function main() {
await client.activate();

// 02-1. create a document then attach it into the client.
const doc = new yorkie.Document<YorkieDoc>(
`codemirror6-${new Date()
.toISOString()
.substring(0, 10)
.replace(/-/g, '')}`,
{
enableDevtools: true,
},
);
// TODO(JOOHOJANG):Put it back to how the document’s dockey was.
const doc = new yorkie.Document<YorkieDoc>('dailysync', {
enableDevtools: true,
});
window.addEventListener('beforeunload', async () => {
await client.detach(doc);
await client.deactivate();
});
window.addEventListener('unload', async () => {
await client.detach(doc);
await client.deactivate();
});
doc.subscribe('connection', (event) => {
network.statusListener(networkStatusElem)(event);
});
Expand Down

0 comments on commit 0c6a7db

Please sign in to comment.