Skip to content

Commit fbc9bc2

Browse files
Reset live counters on sandbox change (codesandbox#3745)
* Reset live counters on sandbox change * Apply suggestions from code review Co-Authored-By: Christian Alfoni <christianalfoni@gmail.com> Co-authored-by: Christian Alfoni <christianalfoni@gmail.com>
1 parent 683cf2c commit fbc9bc2

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class Live {
7171
saved_code: string;
7272
}) => void;
7373

74-
private operationToElixir(ot) {
75-
return ot.map(op => {
74+
private operationToElixir(ot: (number | string)[]) {
75+
return ot.map((op: number | string) => {
7676
if (typeof op === 'number') {
7777
if (op < 0) {
7878
return { d: -op };
@@ -495,6 +495,14 @@ class Live {
495495
});
496496
}
497497

498+
reset() {
499+
this.clients.clear();
500+
501+
clearTimeout(this.awaitSendTimer);
502+
503+
this.awaitSend = null;
504+
}
505+
498506
resetClient(moduleShortid: string, revision: number) {
499507
this.clients.reset(moduleShortid, revision);
500508
}
@@ -522,10 +530,6 @@ class Live {
522530
createClient(moduleShortid: string, revision: number) {
523531
return this.clients.create(moduleShortid, revision);
524532
}
525-
526-
resetClients() {
527-
this.clients.clear();
528-
}
529533
}
530534

531535
export default new Live();

packages/app/src/app/overmind/namespaces/editor/internalActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const initializeLiveSandbox: AsyncAction<Sandbox> = async (
7272
// to join
7373
state.live.joinSource === 'sandbox'
7474
) {
75-
await actions.live.internal.disconnect();
75+
actions.live.internal.disconnect();
7676
}
7777
}
7878

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const reset: Action = ({ state, actions, effects }) => {
4444
state.live.isLoading = false;
4545
state.live.roomInfo = null;
4646
state.live.joinSource = 'sandbox';
47-
effects.live.resetClients();
47+
effects.live.reset();
4848
};
4949

5050
export const disconnect: Action = ({ effects, actions }) => {

0 commit comments

Comments
 (0)