Skip to content

Commit 17d1c12

Browse files
committed
Demo change code from preview
1 parent c435a7b commit 17d1c12

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,24 @@ export const previewActionReceived: Action<any> = (
743743
});
744744
break;
745745
}
746+
747+
case 'source.module.set-code': {
748+
const sandbox = state.editor.currentSandbox;
749+
const module = effects.utils.resolveModule(
750+
action.path.replace(/^\//, ''),
751+
sandbox.modules,
752+
sandbox.directories
753+
);
754+
755+
if (module) {
756+
actions.editor.codeChanged({
757+
moduleShortid: module.shortid,
758+
code: action.code,
759+
});
760+
effects.vscode.setModuleCode(module);
761+
}
762+
break;
763+
}
746764
}
747765
};
748766

packages/codesandbox-api/src/actions/glyph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Action } from './';
1+
import { Action } from '.';
22

33
export interface GlyphOptions {
44
line: number;

packages/codesandbox-api/src/actions/source/dependencies.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { Action } from '../';
1+
import { Action } from '..';
22

3-
export function add(dependencyName: string) {
3+
export interface AddDependencyAction extends Action {
4+
dependency: string;
5+
}
6+
7+
export function add(dependencyName: string): AddDependencyAction {
48
return {
59
type: 'action',
610
action: 'source.dependencies.add',
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1-
import { Action } from '../';
1+
import { Action } from '..';
22

3-
export function rename(path: string, title: string) {
3+
export interface ModuleRenameAction extends Action {
4+
path: string;
5+
title: string;
6+
}
7+
8+
export interface ModuleSetCode extends Action {
9+
path: string;
10+
code: string;
11+
}
12+
13+
export function rename(path: string, title: string): ModuleRenameAction {
414
return {
515
type: 'action',
616
action: 'source.module.rename',
717
path,
818
title,
919
};
1020
}
21+
22+
export function setCode(path: string, code: string): ModuleSetCode {
23+
return {
24+
type: 'action',
25+
action: 'source.module.set-code',
26+
path,
27+
code,
28+
};
29+
}

0 commit comments

Comments
 (0)