Skip to content

Commit b9e9808

Browse files
committed
Reset online clients on attachment cancellation (#1066)
- Fix issue where onlineClients was not cleared after detach, leaving stale presences, by forcing their removal. - Ensure network.js imports in pnpm sdk dev examples follow the same style as other files in the devtool directory. - Replace deleteByID usage in examples with index-based deletion to simplify the interface.
1 parent dcfec68 commit b9e9808

File tree

13 files changed

+33
-55
lines changed

13 files changed

+33
-55
lines changed

examples/nextjs-scheduler/app/page.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,9 @@ export default function Editor() {
5555
// delete selected content at Yorkie's database
5656
deleteContent(date: string) {
5757
doc.update((root) => {
58-
let target;
59-
for (const item of root.content) {
60-
if (item.date === date) {
61-
target = item;
62-
break;
63-
}
64-
}
65-
66-
if (target) {
67-
root.content.deleteByID!(target.getID());
58+
const idx = root.content.findIndex((item) => item.date === date);
59+
if (idx !== -1) {
60+
root.content.delete?.(idx);
6861
}
6962
});
7063
},

examples/nextjs-todolist/components/TodoList.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ const TodoList = () => {
4848

4949
const deleteTodo = (id: string) => {
5050
update((root) => {
51-
for (const todo of root.todos) {
52-
if (todo.id === id) {
53-
root.todos.deleteByID!(todo.getID!());
54-
break;
55-
}
51+
const idx = root.todos.findIndex((todo) => todo.id === id);
52+
if (idx !== -1) {
53+
root.todos.delete?.(idx);
5654
}
5755
});
5856
};

examples/react-flow/src/App.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import '@xyflow/react/dist/style.css';
1414
import './App.css';
1515

1616
type Graph = {
17-
nodes: JSONArray<JSONObject<Node>>;
18-
edges: JSONArray<JSONObject<Edge>>;
17+
nodes: JSONArray<Node>;
18+
edges: JSONArray<Edge>;
1919
};
2020

2121
function App() {
@@ -38,7 +38,7 @@ function App() {
3838
case 'remove':
3939
{
4040
const idx = r.nodes.findIndex((n) => n.id === c.id);
41-
r.nodes.deleteByID!(r.nodes[idx].getID!());
41+
r.nodes.delete?.(idx);
4242
}
4343
break;
4444
case 'position':
@@ -79,7 +79,7 @@ function App() {
7979
case 'remove':
8080
{
8181
const idx = r.edges.findIndex((e) => e.id === c.id);
82-
r.edges.deleteByID!(r.edges[idx].getID!());
82+
r.edges.delete?.(idx);
8383
}
8484
break;
8585
case 'select':

examples/vuejs-kanban/src/App.vue

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,15 @@ import yorkie from '@yorkie-js/sdk';
44
const defaultLists = [
55
{
66
title: 'Todo',
7-
cards: [
8-
{
9-
title: 'Pruning document',
10-
},
11-
{
12-
title: 'Clean up codes',
13-
},
14-
],
7+
cards: [{ title: 'Pruning document' }, { title: 'Clean up codes' }],
158
},
169
{
1710
title: 'Doing',
18-
cards: [
19-
{
20-
title: 'Array operations',
21-
},
22-
],
11+
cards: [{ title: 'Array operations' }],
2312
},
2413
{
2514
title: 'Done',
26-
cards: [
27-
{
28-
title: 'Create a sample page',
29-
},
30-
{
31-
title: 'Launch demo site',
32-
},
33-
],
15+
cards: [{ title: 'Create a sample page' }, { title: 'Launch demo site' }],
3416
},
3517
];
3618

packages/sdk/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ <h4 class="title">
184184
</div>
185185
</div>
186186
</div>
187-
<script src="./util.js"></script>
188187
<script src="./devtool/text.js"></script>
189188
<script type="module">
190189
import './src/yorkie.ts';
190+
import Network from './public/devtool/network.js';
191191

192192
const textarea = document.getElementById('textarea');
193193
const statusHolder = document.getElementById('network-status');

packages/sdk/public/counter.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
<button id="decreaseButton">-</button>
1616
</div>
1717
</div>
18-
<script src="./util.js"></script>
1918
<script type="module">
2019
import './src/yorkie.ts';
20+
import Network from './devtool/network.js';
21+
2122
const statusHolder = document.getElementById('network-status');
2223
const onlineClientsHolder = document.getElementById('online-clients');
2324
const counter = document.getElementById('counter');

packages/sdk/public/util.js renamed to packages/sdk/public/devtool/network.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* `Network` is a class that manages the network status.
33
*/
4-
export class Network {
4+
export default class Network {
55
constructor(elem) {
66
this.isOnline = false;
77
this.elem = elem;

packages/sdk/public/multi.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ <h2>Quill Editor</h2>
3636
<h2>yorkie document</h2>
3737
<pre style="white-space: pre-wrap" id="log-holder"></pre>
3838
</div>
39-
<script src="./util.js"></script>
4039
<script type="module">
4140
import './src/yorkie.ts';
41+
import Network from './devtool/network.js';
42+
4243
const statusHolder = document.getElementById('network-status');
4344
const placeholder = document.getElementById('placeholder');
4445
const onlineClientsHolder = document.getElementById('online-clients');

packages/sdk/public/quill-two-clients.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@
117117
<div class="online-clients"></div>
118118
</div>
119119
</div>
120-
<script src="./util.js"></script>
121120
<script type="module">
122121
import './src/yorkie.ts';
122+
import Network from './devtool/network.js';
123+
123124
const colorHash = new ColorHash();
124125
const clientAElem = document.getElementById('client-a');
125126
const clientBElem = document.getElementById('client-b');

packages/sdk/public/quill.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
<div id="editor"></div>
2020
<div id="document"></div>
2121
<div id="document-text"></div>
22-
<script src="./util.js"></script>
2322
<script type="module">
2423
import './src/yorkie.ts';
24+
import Network from './devtool/network.js';
25+
2526
const onlineClientsElem = document.getElementById('online-clients');
2627
const documentElem = document.getElementById('document');
2728
const documentTextElem = document.getElementById('document-text');

0 commit comments

Comments
 (0)