Skip to content

Commit edcaec2

Browse files
Simplify outbound queue API
1 parent db35221 commit edcaec2

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

examples/playground/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ export default function App() {
469469
liveAllEnabled,
470470
setLiveAllEnabled,
471471
toggleLiveChildren,
472-
queueLocalOpsForSync,
472+
queueOpsForSync,
473473
handleSync,
474474
handleScopedSync,
475475
postBroadcastMessage,
@@ -500,10 +500,10 @@ export default function App() {
500500
const handleCommittedLocalOps = React.useCallback(
501501
(ops: Operation[]) => {
502502
// The local write already committed. This only feeds playground sync and debug UI state.
503-
queueLocalOpsForSync(ops);
503+
queueOpsForSync(ops);
504504
recordOps(ops, { assumeSorted: true });
505505
},
506-
[queueLocalOpsForSync, recordOps]
506+
[queueOpsForSync, recordOps]
507507
);
508508

509509
const grantSubtreeToReplicaPubkey = React.useCallback(

examples/playground/src/playground/hooks/usePlaygroundSync.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ type PlaygroundSyncApi = {
9696
liveAllEnabled: boolean;
9797
setLiveAllEnabled: React.Dispatch<React.SetStateAction<boolean>>;
9898
toggleLiveChildren: (parentId: string) => void;
99-
queueLocalOpsForSync: (ops?: Operation[]) => void;
99+
queueOpsForSync: (ops?: Operation[]) => void;
100100
handleSync: (filter: Filter) => Promise<void>;
101101
handleScopedSync: () => Promise<void>;
102102
postBroadcastMessage: (
@@ -204,9 +204,9 @@ export function usePlaygroundSync(opts: UsePlaygroundSyncOptions): PlaygroundSyn
204204
const autoSyncAttemptRef = useRef(0);
205205
const autoSyncPeerIdRef = useRef<string | null>(null);
206206

207-
const queueLocalOpsForSync = (ops?: Operation[]) => {
207+
const queueOpsForSync = (ops?: Operation[]) => {
208208
void syncPeerRef.current?.notifyLocalUpdate(ops);
209-
outboundSyncRef.current?.queueLocalOps(ops);
209+
outboundSyncRef.current?.queue(ops);
210210
};
211211

212212
const dropPeerConnection = (peerId: string) => {
@@ -729,7 +729,7 @@ export function usePlaygroundSync(opts: UsePlaygroundSyncOptions): PlaygroundSyn
729729
liveAllEnabled,
730730
setLiveAllEnabled,
731731
toggleLiveChildren,
732-
queueLocalOpsForSync,
732+
queueOpsForSync,
733733
handleSync,
734734
handleScopedSync,
735735
postBroadcastMessage,

packages/treecrdt-sync/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ outbound.addPeer('remote:server', websocketTransport);
6464

6565
const op = await client.local.payload(replica, node, payload);
6666
await peer.notifyLocalUpdate([op]); // local mesh fanout
67-
outbound.queueLocalOps([op]); // remote websocket upload/retry
67+
outbound.queue([op]); // remote websocket upload/retry
6868
```
6969

7070
## When not to

packages/treecrdt-sync/src/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export type OutboundSync<Op = Operation> = {
110110
addPeer: (peerId: string, transport: DuplexTransport<SyncMessage<Op>>) => void;
111111
removePeer: (peerId: string) => void;
112112
clearPeers: () => void;
113-
queueLocalOps: (ops?: readonly Op[]) => void;
113+
queue: (ops?: readonly Op[]) => void;
114114
flush: () => Promise<void>;
115115
close: () => void;
116116
};
@@ -525,7 +525,7 @@ export function createOutboundSync<Op = Operation>(
525525
peers.clear();
526526
emitStatus();
527527
},
528-
queueLocalOps: (ops = []) => {
528+
queue: (ops = []) => {
529529
if (closed) return;
530530
if (ops.length > 0) addPendingOps(ops);
531531
else needsFullSync = true;

packages/treecrdt-sync/tests/controller.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ test('outbound sync queues local ops until a selected peer is available', async
220220
shouldSyncPeer: (peerId) => peerId.startsWith('remote:'),
221221
});
222222

223-
controller.queueLocalOps([op, op]);
223+
controller.queue([op, op]);
224224
await controller.flush();
225225

226226
expect(controller.pendingOpCount).toBe(1);
@@ -250,7 +250,7 @@ test('outbound sync keeps failed direct pushes queued', async () => {
250250
});
251251
controller.addPeer('remote:server', {} as any);
252252

253-
controller.queueLocalOps([op]);
253+
controller.queue([op]);
254254
await controller.flush();
255255

256256
expect(controller.pendingOpCount).toBe(1);
@@ -272,7 +272,7 @@ test('outbound sync runs fallback sync when no exact ops are available', async (
272272
});
273273
controller.addPeer('remote:server', {} as any);
274274

275-
controller.queueLocalOps();
275+
controller.queue();
276276
await controller.flush();
277277

278278
expect(controller.pendingOpCount).toBe(0);

0 commit comments

Comments
 (0)