Skip to content

Commit 16eb666

Browse files
improve transpilation indication
1 parent 7723f8e commit 16eb666

File tree

17 files changed

+173
-139
lines changed

17 files changed

+173
-139
lines changed

packages/app/src/app/overmind/effects/preview.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ export default {
3333
_preview = blocker<any>();
3434
};
3535
},
36-
async executeCodeImmediately(initialRender?: boolean) {
36+
async executeCodeImmediately({
37+
initialRender = false,
38+
showFullScreen = false,
39+
} = {}) {
3740
const preview = await _preview.promise;
38-
preview.executeCodeImmediately(initialRender);
41+
preview.executeCodeImmediately(initialRender, showFullScreen);
3942
},
4043
async executeCode() {
4144
const preview = await _preview.promise;

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ export function getCurrentModelPath(editor) {
2626
return model.uri.path.replace(/^\/sandbox/, '');
2727
}
2828

29-
export function getCode(editor) {
30-
const activeEditor = editor.getActiveCodeEditor();
31-
32-
if (!activeEditor) return '';
33-
34-
return activeEditor.getValue();
35-
}
36-
3729
export function getCurrentModel(editor) {
3830
const activeEditor = editor.getActiveCodeEditor();
3931

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from '@codesandbox/common/lib/types';
1010
import { Action, AsyncAction } from 'app/overmind';
1111
import { withLoadApp, withOwnedSandbox } from 'app/overmind/factories';
12-
import { sortObjectByKeys } from 'app/overmind/utils/common';
1312
import getItems from 'app/overmind/utils/items';
1413
import {
1514
addDevToolsTab as addDevToolsTabUtil,
@@ -45,24 +44,19 @@ export const addNpmDependency: AsyncAction<{
4544
version: newVersion,
4645
isDev: Boolean(isDev),
4746
});
47+
48+
effects.preview.executeCodeImmediately();
4849
}
4950
);
5051

5152
export const npmDependencyRemoved: AsyncAction<{
5253
name: string;
53-
}> = withOwnedSandbox(async ({ state, effects, actions }, { name }) => {
54+
}> = withOwnedSandbox(async ({ effects, actions }, { name }) => {
5455
effects.analytics.track('Remove NPM Dependency');
5556

56-
const { parsed } = state.editor.parsedConfigurations.package;
57-
58-
delete parsed.dependencies[name];
59-
parsed.dependencies = sortObjectByKeys(parsed.dependencies);
57+
await actions.editor.internal.removeNpmDependencyFromPackageJson(name);
6058

61-
await actions.editor.internal.saveCode({
62-
code: JSON.stringify(parsed, null, 2),
63-
moduleShortid: state.editor.currentPackageJSON.shortid,
64-
cbID: null,
65-
});
59+
effects.preview.executeCodeImmediately();
6660
});
6761

6862
export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
@@ -127,7 +121,7 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
127121
}
128122

129123
effects.vscode.openModule(state.editor.currentModule);
130-
effects.preview.executeCodeImmediately(true);
124+
effects.preview.executeCodeImmediately({ initialRender: true });
131125

132126
state.editor.isLoading = false;
133127
});

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,36 @@ export const updateCurrentTemplate: AsyncAction = async ({
224224
}
225225
};
226226

227+
export const removeNpmDependencyFromPackageJson: AsyncAction<string> = async (
228+
{ state, actions },
229+
name
230+
) => {
231+
const packageJson = JSON.parse(state.editor.currentPackageJSONCode);
232+
233+
delete packageJson.dependencies[name];
234+
235+
await actions.editor.internal.saveCode({
236+
code: JSON.stringify(packageJson, null, 2),
237+
moduleShortid: state.editor.currentPackageJSON.shortid,
238+
cbID: null,
239+
});
240+
};
241+
227242
export const addNpmDependencyToPackageJson: AsyncAction<{
228243
name: string;
229244
version?: string;
230245
isDev: boolean;
231246
}> = async ({ state, actions }, { name, isDev, version }) => {
232-
const { parsed } = state.editor.parsedConfigurations.package;
247+
const packageJson = JSON.parse(state.editor.currentPackageJSONCode);
233248

234249
const type = isDev ? 'devDependencies' : 'dependencies';
235250

236-
parsed[type] = parsed[type] || {};
237-
parsed[type][name] = version || 'latest';
238-
parsed[type] = sortObjectByKeys(parsed[type]);
251+
packageJson[type] = packageJson[type] || {};
252+
packageJson[type][name] = version || 'latest';
253+
packageJson[type] = sortObjectByKeys(packageJson[type]);
239254

240255
await actions.editor.internal.saveCode({
241-
code: JSON.stringify(parsed, null, 2),
256+
code: JSON.stringify(packageJson, null, 2),
242257
moduleShortid: state.editor.currentPackageJSON.shortid,
243258
cbID: null,
244259
});
@@ -322,29 +337,14 @@ export const forkSandbox: AsyncAction<{
322337
});
323338
}
324339

325-
// When we have a server we want to set a brand new sandbox,
326-
// as the preview also needs to be managed correctly
327-
if (getTemplateDefinition(forkedSandbox.template).isServer) {
328-
await effects.vscode.closeAllTabs();
329-
actions.internal.setCurrentSandbox(forkedSandbox);
330-
await effects.vscode.changeSandbox(forkedSandbox, fs => {
331-
state.editor.modulesByPath = fs;
332-
});
333-
334-
effects.preview.executeCodeImmediately(true);
335-
336-
// When not server we "piggyback" the existing Sandbox to avoid any rerenders and need
337-
// for new bundler. Preview updates its url though
338-
} else {
339-
Object.assign(
340-
state.editor.sandboxes[state.editor.currentId],
341-
forkedSandbox
342-
);
343-
state.editor.modulesByPath = effects.vscode.sandboxFsSync.create(
344-
forkedSandbox
345-
);
346-
effects.preview.updateAddressbarUrl();
347-
}
340+
Object.assign(
341+
state.editor.sandboxes[state.editor.currentId],
342+
forkedSandbox
343+
);
344+
state.editor.modulesByPath = effects.vscode.sandboxFsSync.create(
345+
forkedSandbox
346+
);
347+
effects.preview.updateAddressbarUrl();
348348

349349
effects.notificationToast.success('Forked sandbox!');
350350
effects.router.updateSandboxUrl(forkedSandbox);

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const roomJoined: AsyncAction<{
3333
});
3434

3535
effects.vscode.openModule(state.editor.currentModule);
36-
effects.preview.executeCodeImmediately(true);
36+
effects.preview.executeCodeImmediately({ initialRender: true });
3737
state.live.isLoading = false;
3838
});
3939

@@ -53,7 +53,7 @@ export const createLiveClicked: AsyncAction<{
5353
});
5454

5555
effects.vscode.openModule(state.editor.currentModule);
56-
effects.preview.executeCodeImmediately(true);
56+
effects.preview.executeCodeImmediately({ initialRender: true });
5757
};
5858

5959
export const liveMessageReceived: Operator<LiveMessage> = pipe(
@@ -92,15 +92,9 @@ export const applyTransformation: Action<{
9292
operation: any;
9393
moduleShortid: string;
9494
}> = ({ state, effects }, { operation, moduleShortid }) => {
95-
state.live.receivingCode = false;
96-
9795
effects.vscode.applyOperation(moduleShortid, operation);
9896
};
9997

100-
export const onCodeReceived: Action = ({ state }) => {
101-
state.live.receivingCode = false;
102-
};
103-
10498
export const onSelectionChanged: Action<any> = (
10599
{ state, effects },
106100
selection

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ export const initialize: AsyncAction<string, Sandbox> = async (
7575
effects.analytics.track('Live Session Joined', {});
7676
effects.live.listen(actions.live.liveMessageReceived);
7777

78-
state.live.receivingCode = true;
7978
actions.live.internal.initializeModuleState(moduleState);
80-
state.live.receivingCode = false;
79+
8180
state.live.isLive = true;
8281
state.live.error = null;
8382
effects.live.sendModuleState();

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ export const onJoin: Operator<LiveMessage<{
3333
export const onModuleState: Operator<LiveMessage<{
3434
module_state: any;
3535
}>> = mutate(({ state, actions }, { data }) => {
36-
// We get this when we notice that there is an out of sync
37-
// Really no reason to set this state as everything runs sync
38-
state.live.receivingCode = true;
3936
actions.live.internal.initializeModuleState(data.module_state);
40-
state.live.receivingCode = false;
4137
});
4238

4339
export const onUserEntered: Operator<LiveMessage<{

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { RoomInfo, LiveUser } from '@codesandbox/common/lib/types';
1+
import { LiveUser, RoomInfo } from '@codesandbox/common/lib/types';
22
import { Derive } from 'app/overmind';
33

44
type State = {
55
isLive: boolean;
66
isTeam: boolean;
77
isLoading: boolean;
8-
receivingCode: boolean;
98
error: string;
109
reconnecting: boolean;
1110
notificationsHidden: boolean;
@@ -28,7 +27,6 @@ export const state: State = {
2827
isLive: false,
2928
isTeam: false,
3029
isLoading: false,
31-
receivingCode: false,
3230
reconnecting: false,
3331
notificationsHidden: false,
3432
followingUserId: null,

packages/app/src/sandbox/boilerplates/index.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// @flow
2-
import type { Module } from '../eval/entities/module';
3-
41
import { getCurrentManager } from '../compile';
52

63
let cachedBoilerplates = [];
74

8-
export async function evalBoilerplates(boilerplates: Array<any>) {
5+
export async function evalBoilerplates(boilerplates) {
96
cachedBoilerplates = await Promise.all(
107
boilerplates.map(async boilerplate => {
11-
const fakeModule: Module = {
8+
const fakeModule = {
129
path: `/boilerplate-${boilerplate.condition}${boilerplate.extension}`,
1310
code: boilerplate.code,
1411
};
@@ -23,11 +20,11 @@ export async function evalBoilerplates(boilerplates: Array<any>) {
2320
);
2421
}
2522

26-
export function getBoilerplates(): Array<any> {
23+
export function getBoilerplates() {
2724
return cachedBoilerplates;
2825
}
2926

30-
export function findBoilerplate(module: Module): any {
27+
export function findBoilerplate(module) {
3128
const boilerplates = getBoilerplates();
3229
const boilerplate = boilerplates.find(b => {
3330
const regex = new RegExp(b.condition);
@@ -36,9 +33,7 @@ export function findBoilerplate(module: Module): any {
3633

3734
if (boilerplate == null) {
3835
throw new Error(
39-
`No boilerplate found for ${
40-
module.path
41-
}, you can create one in the future`
36+
`No boilerplate found for ${module.path}, you can create one in the future`
4237
);
4338
}
4439

packages/app/src/sandbox/compile.ts

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
1-
import { dispatch, reattach, clearErrorTransformers } from 'codesandbox-api';
2-
import { flatten } from 'lodash';
3-
import { absolute } from '@codesandbox/common/lib/utils/path';
4-
import _debug from '@codesandbox/common/lib/utils/debug';
51
import parseConfigurations from '@codesandbox/common/lib/templates/configuration/parse';
6-
import initializeErrorTransformers from 'sandbox-hooks/errors/transformers';
7-
import { inject, unmount } from 'sandbox-hooks/react-error-overlay/overlay';
8-
import { isBabel7 } from '@codesandbox/common/lib/utils/is-babel-7';
9-
import { ParsedConfigurationFiles } from '@codesandbox/common/lib/templates/template';
102
import getDefinition, {
113
TemplateType,
124
} from '@codesandbox/common/lib/templates/index';
13-
14-
import getPreset from './eval';
15-
import Manager, { Manifest } from './eval/manager';
16-
17-
import { resetScreen } from './status-screen';
18-
19-
import createCodeSandboxOverlay from './codesandbox-overlay';
20-
import handleExternalResources from './external-resources';
21-
22-
import defaultBoilerplates from './boilerplates/default-boilerplates';
5+
import { ParsedConfigurationFiles } from '@codesandbox/common/lib/templates/template';
6+
import _debug from '@codesandbox/common/lib/utils/debug';
7+
import { isBabel7 } from '@codesandbox/common/lib/utils/is-babel-7';
8+
import { absolute } from '@codesandbox/common/lib/utils/path';
9+
import { clearErrorTransformers, dispatch, reattach } from 'codesandbox-api';
10+
import { flatten } from 'lodash';
11+
import initializeErrorTransformers from 'sandbox-hooks/errors/transformers';
12+
import { inject, unmount } from 'sandbox-hooks/react-error-overlay/overlay';
2313

2414
import {
25-
getBoilerplates,
2615
evalBoilerplates,
2716
findBoilerplate,
28-
} from './boilerplates'; // eslint-disable-line
29-
30-
import { loadDependencies } from './npm';
31-
import { consumeCache, saveCache, deleteAPICache } from './eval/cache';
32-
33-
import { showRunOnClick } from './status-screen/run-on-click';
17+
getBoilerplates,
18+
} from './boilerplates';
19+
import defaultBoilerplates from './boilerplates/default-boilerplates';
20+
import createCodeSandboxOverlay from './codesandbox-overlay';
21+
import getPreset from './eval';
22+
import { consumeCache, deleteAPICache, saveCache } from './eval/cache';
3423
import { Module } from './eval/entities/module';
24+
import Manager, { Manifest } from './eval/manager';
3525
import TranspiledModule from './eval/transpiled-module';
26+
import handleExternalResources from './external-resources';
27+
import { loadDependencies } from './npm';
28+
import { resetScreen } from './status-screen';
29+
import { showRunOnClick } from './status-screen/run-on-click';
3630

3731
let initializedResizeListener = false;
3832
let manager: Manager | null = null;
@@ -408,6 +402,7 @@ interface CompileOptions {
408402
skipEval?: boolean;
409403
hasFileResolver?: boolean;
410404
disableDependencyPreprocessing?: boolean;
405+
showFullScreen?: boolean;
411406
}
412407

413408
async function compile({
@@ -422,6 +417,7 @@ async function compile({
422417
skipEval = false,
423418
hasFileResolver = false,
424419
disableDependencyPreprocessing = false,
420+
showFullScreen = false,
425421
}: CompileOptions) {
426422
dispatch({
427423
type: 'start',
@@ -456,9 +452,7 @@ async function compile({
456452

457453
if (errors.length) {
458454
const e = new Error(
459-
`We weren't able to parse: '${errors[0].path}': ${
460-
errors[0].error.message
461-
}`
455+
`We weren't able to parse: '${errors[0].path}': ${errors[0].error.message}`
462456
);
463457

464458
// @ts-ignore
@@ -488,6 +482,7 @@ async function compile({
488482
{
489483
disableExternalConnection: disableDependencyPreprocessing,
490484
resolutions: parsedPackageJSON.resolutions,
485+
showFullScreen,
491486
}
492487
);
493488

@@ -519,9 +514,7 @@ async function compile({
519514

520515
if (!foundMain) {
521516
throw new Error(
522-
`Could not find entry file: ${
523-
possibleEntries[0]
524-
}. You can specify one in package.json by defining a \`main\` property.`
517+
`Could not find entry file: ${possibleEntries[0]}. You can specify one in package.json by defining a \`main\` property.`
525518
);
526519
}
527520

0 commit comments

Comments
 (0)