Skip to content

Commit 17c9b7f

Browse files
christianalfoniCompuIves
authored andcommitted
Improve perf even more (codesandbox#2609)
1 parent 221a4ba commit 17c9b7f

File tree

7 files changed

+25
-19
lines changed

7 files changed

+25
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
import { client } from 'app/graphql/client';
2323
import { LIST_TEMPLATES } from 'app/pages/Dashboard/queries';
2424

25-
import apiFactory, { Api, ApiConfig } from './apiFactory';
2625
import { transformSandbox } from '../utils/sandbox';
26+
import apiFactory, { Api, ApiConfig } from './apiFactory';
2727

2828
let api: Api;
2929

packages/app/src/app/overmind/effects/utils/sandbox.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Sandbox } from '@codesandbox/common/lib/types';
2+
13
export function transformSandbox(sandbox: Sandbox) {
24
// We need to add client side properties for tracking
35
return {
@@ -8,6 +10,11 @@ export function transformSandbox(sandbox: Sandbox) {
810
isNotSynced: false,
911
errors: [],
1012
corrections: [],
13+
type: 'file' as 'file',
14+
})),
15+
directories: sandbox.directories.map(directory => ({
16+
...directory,
17+
type: 'directory' as 'directory',
1118
})),
1219
};
1320
}

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,13 @@ export const state: State = {
187187
const pathItem = modulePaths[path];
188188

189189
if (pathItem.type === 'file') {
190-
modulesByPath[path] = {
191-
...modulePaths[path],
192-
...currentSandbox.modules.find(
193-
moduleItem => moduleItem.shortid === pathItem.shortid
194-
),
195-
};
190+
modulesByPath[path] = currentSandbox.modules.find(
191+
moduleItem => moduleItem.shortid === pathItem.shortid
192+
);
196193
} else {
197-
modulesByPath[path] = {
198-
...modulePaths[path],
199-
...currentSandbox.directories.find(
200-
moduleItem => moduleItem.shortid === pathItem.shortid
201-
),
202-
};
194+
modulesByPath[path] = currentSandbox.directories.find(
195+
moduleItem => moduleItem.shortid === pathItem.shortid
196+
);
203197
}
204198
});
205199

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { AsyncAction } from 'app/overmind';
21
import { getModulePath } from '@codesandbox/common/lib/sandbox/modules';
32
import getDefinition from '@codesandbox/common/lib/templates';
4-
import denormalize from 'codesandbox-import-utils/lib/utils/files/denormalize';
5-
import { INormalizedModules } from 'codesandbox-import-util-types';
63
import { ModuleTab } from '@codesandbox/common/lib/types';
7-
import { createOptimisticModule } from 'app/overmind/utils/common';
4+
import { AsyncAction } from 'app/overmind';
85
import { withOwnedSandbox } from 'app/overmind/factories';
6+
import { createOptimisticModule } from 'app/overmind/utils/common';
7+
import { INormalizedModules } from 'codesandbox-import-util-types';
8+
import denormalize from 'codesandbox-import-utils/lib/utils/files/denormalize';
9+
910
import {
10-
resolveModuleWrapped,
1111
resolveDirectoryWrapped,
12+
resolveModuleWrapped,
1213
} from '../../utils/resolve-module-wrapped';
1314
import * as internalActions from './internalActions';
1415

@@ -59,6 +60,7 @@ export const directoryCreated: AsyncAction<{
5960
sourceId: state.editor.currentSandbox.sourceId,
6061
insertedAt: new Date().toString(),
6162
updatedAt: new Date().toString(),
63+
type: 'directory' as 'directory',
6264
};
6365

6466
sandbox.directories.push(optimisticDirectory);

packages/app/src/app/overmind/onInitialize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const onInitialize: OnInitialize = (
99
effects.fsSync.initialize({
1010
onModulesByPathChange(cb: (modulesByPath: any) => void) {
1111
overmindInstance.reaction(
12-
({ editor }) => editor.modulesByPath,
12+
({ editor }) => editor.modulePaths,
1313
({ editor }) => cb(editor.modulesByPath)
1414
);
1515
},

packages/app/src/app/overmind/utils/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export function createOptimisticModule(overrides: Partial<Module>) {
2020
isNotSynced: true,
2121
errors: [],
2222
corrections: [],
23+
type: 'file' as 'file',
2324
...overrides,
2425
};
2526
}

packages/common/src/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export type Module = {
5858
updatedAt: string;
5959
path?: string;
6060
now?: any;
61+
type: 'file';
6162
};
6263

6364
export type Directory = {
@@ -66,6 +67,7 @@ export type Directory = {
6667
directoryShortid: string | undefined;
6768
shortid: string;
6869
sourceId: string;
70+
type: 'directory';
6971
};
7072

7173
export type Template = {

0 commit comments

Comments
 (0)