Skip to content

Commit 86a7822

Browse files
fix typing
1 parent a354377 commit 86a7822

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Live {
209209
reconnect_token: result.reconnectToken,
210210
});
211211

212-
this.presence = new Presence(this.channel);
212+
this.presence = new Presence(this.channel!);
213213
this.presence.onSync(() => {
214214
this.connectionsCount = this.presence.list().length;
215215
});

packages/app/src/app/overmind/effects/vscode/ModelsHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ export class ModelsHandler {
308308
*/
309309
public setModuleCode(module: Module, triggerChangeEvent = false) {
310310
const moduleModel = this.getModuleModelByPath(module.path);
311-
const model = moduleModel.model;
311+
const model = moduleModel?.model;
312312

313313
if (!model) {
314314
return;

packages/app/src/app/overmind/namespaces/comments/actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export const addComment: AsyncAction<{
369369
lastUpdatedAt: sandbox.modules.find(
370370
module =>
371371
module.path === optimisticComment.references[0].metadata.path
372-
)?.updatedAt,
372+
)!.updatedAt,
373373
}
374374
: null,
375375
});
@@ -526,6 +526,10 @@ export const onCommentAdded: Action<CommentAddedSubscription> = (
526526
if (comment.references[0] && comment.references[0].type === 'code') {
527527
const codeReference = comment.references[0].metadata;
528528
const sandbox = state.editor.currentSandbox;
529+
if (!sandbox) {
530+
return;
531+
}
532+
529533
const module = sandbox.modules.find(
530534
moduleItem => moduleItem.path === codeReference.path
531535
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ export const saveClicked: AsyncAction = withOwnedSandbox(
441441
state.editor.changedModuleShortids.includes(module.shortid)
442442
);
443443

444-
if (COMMENTS) {
444+
if (state.user?.experiments.comments) {
445445
const versions = await Promise.all(
446446
changedModules.map(module =>
447447
effects.live

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
ServerContainerStatus,
99
TabType,
1010
} from '@codesandbox/common/lib/types';
11-
import { COMMENTS } from '@codesandbox/common/lib/utils/feature-flags';
1211
import { hasPermission } from '@codesandbox/common/lib/utils/permission';
1312
import slugify from '@codesandbox/common/lib/utils/slugify';
1413
import {
@@ -127,7 +126,7 @@ export const saveCode: AsyncAction<{
127126
}
128127

129128
try {
130-
if (COMMENTS) {
129+
if (state.user?.experiments.comments) {
131130
const {
132131
saved_code,
133132
updated_at,
@@ -273,6 +272,7 @@ export const removeNpmDependencyFromPackageJson: AsyncAction<string> = async (
273272
name
274273
) => {
275274
if (
275+
!state.editor.currentSandbox ||
276276
!state.editor.currentPackageJSONCode ||
277277
!state.editor.currentPackageJSON
278278
) {
@@ -309,6 +309,7 @@ export const addNpmDependencyToPackageJson: AsyncAction<{
309309
isDev: boolean;
310310
}> = async ({ state, actions, effects }, { name, isDev, version }) => {
311311
if (
312+
!state.editor.currentSandbox ||
312313
!state.editor.currentPackageJSONCode ||
313314
!state.editor.currentPackageJSON
314315
) {
@@ -522,9 +523,7 @@ export const updateSandboxPackageJson: AsyncAction = async ({
522523
const code = JSON.stringify(parsed, null, 2);
523524
const moduleShortid = state.editor.currentPackageJSON.shortid;
524525

525-
const module = state.editor.currentSandbox.modules.find(
526-
m => m.shortid === moduleShortid
527-
);
526+
const module = sandbox.modules.find(m => m.shortid === moduleShortid);
528527

529528
if (!module) {
530529
return;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,27 @@ import { json, mutate } from 'overmind';
1717

1818
export const onSave: Operator<LiveMessage<{
1919
saved_code: string;
20+
updated_at: string;
21+
inserted_at: string;
2022
version: number;
2123
path: string;
22-
}>> = mutate(({ effects, actions, state }, { data }) => {
24+
}>> = mutate(({ state }, { data }) => {
2325
const sandbox = state.editor.currentSandbox;
26+
27+
if (!sandbox) {
28+
return;
29+
}
2430
const module = sandbox.modules.find(
2531
moduleItem => moduleItem.path === data.path
2632
);
2733

34+
if (!module) {
35+
return;
36+
}
37+
2838
module.savedCode = data.saved_code;
39+
module.updatedAt = data.updated_at;
40+
module.insertedAt = data.inserted_at;
2941
sandbox.version = data.version;
3042
});
3143

0 commit comments

Comments
 (0)