Skip to content

Commit 691a33e

Browse files
committed
Acknowledge operations from the response from the server
1 parent dd52d75 commit 691a33e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

packages/app/src/app/overmind/effects/live/clients.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type SendOperation = (
44
moduleShortid: string,
55
revision: string,
66
operation: any
7-
) => void;
7+
) => Promise<unknown>;
88

99
export type ApplyOperation = (moduleShortid: string, operation: any) => void;
1010

@@ -24,13 +24,13 @@ function operationToElixir(ot) {
2424

2525
class CodeSandboxOTClient extends Client {
2626
moduleShortid: string;
27-
onSendOperation: (revision: string, operation: any) => void;
27+
onSendOperation: (revision: string, operation: any) => Promise<unknown>;
2828
onApplyOperation: (operation: any) => void;
2929

3030
constructor(
3131
revision: number,
3232
moduleShortid: string,
33-
onSendOperation: (revision: string, operation: any) => void,
33+
onSendOperation: (revision: string, operation: any) => Promise<unknown>,
3434
onApplyOperation: (operation: any) => void
3535
) {
3636
super(revision);
@@ -40,7 +40,11 @@ class CodeSandboxOTClient extends Client {
4040
}
4141

4242
sendOperation(revision, operation) {
43-
this.onSendOperation(revision, operationToElixir(operation.toJSON()));
43+
this.onSendOperation(revision, operationToElixir(operation.toJSON())).then(
44+
() => {
45+
this.serverAck();
46+
}
47+
);
4448
}
4549

4650
applyOperation(operation) {
@@ -96,9 +100,8 @@ export default (
96100
const client = new CodeSandboxOTClient(
97101
initialRevision,
98102
moduleShortid,
99-
(revision, operation) => {
100-
sendOperation(moduleShortid, revision, operation);
101-
},
103+
(revision, operation) =>
104+
sendOperation(moduleShortid, revision, operation),
102105
operation => {
103106
applyOperation(moduleShortid, operation);
104107
}

packages/app/src/app/overmind/effects/live/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@ export default new (class Live {
4444
const live = this;
4545

4646
clients = clientsFactory(
47-
(moduleShortid, revision, operation) => {
47+
(moduleShortid, revision, operation) =>
4848
live.send('operation', {
4949
moduleShortid,
5050
operation,
5151
revision,
52-
});
53-
},
52+
}),
5453
(moduleShortid, operation) => {
5554
options.onApplyOperation({
5655
moduleShortid,

packages/app/src/app/overmind/namespaces/live/liveMessageOperators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ export const onOperation: Operator<LiveMessage<{
481481
return;
482482
}
483483
if (_isOwnMessage) {
484-
effects.live.serverAck(data.module_shortid);
484+
// Do nothing since we already sent this operation
485485
} else {
486486
try {
487487
effects.live.applyServer(data.module_shortid, data.operation);

0 commit comments

Comments
 (0)