Skip to content

Commit e804445

Browse files
leeyi45martin-henzNhatMinh0208
authored
Module Loading Changes (#2871)
* Remove side content state from workspaces and story env * Run format * Fix broken import * Change to new tab loading system * Merge * Fix wrongly named type * Run format * bumping js-slang * update mock context --------- Co-authored-by: henz <henz@comp.nus.edu.sg> Co-authored-by: NhatMinh0208 <minhkhicon2468@gmail.com>
1 parent 72873e6 commit e804445

File tree

10 files changed

+18
-27
lines changed

10 files changed

+18
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"flexboxgrid": "^6.3.1",
5050
"flexboxgrid-helpers": "^1.1.3",
5151
"hastscript": "^9.0.0",
52-
"js-slang": "^1.0.51",
52+
"js-slang": "^1.0.52",
5353
"js-yaml": "^4.1.0",
5454
"konva": "^9.2.0",
5555
"lodash": "^4.17.21",

src/commons/application/ApplicationTypes.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,6 @@ export const createDefaultWorkspace = (workspaceLocation: WorkspaceLocation): Wo
381381
isDebugging: false,
382382
enableDebugging: true,
383383
debuggerContext: {} as DebuggerContext,
384-
sideContent: {
385-
alerts: [],
386-
dynamicTabs: []
387-
},
388384
lastDebuggerResult: undefined,
389385
lastNonDetResult: null
390386
});
@@ -527,11 +523,7 @@ export const createDefaultStoriesEnv = (
527523
stepLimit: 1000,
528524
globals: [],
529525
usingSubst: false,
530-
debuggerContext: {} as DebuggerContext,
531-
sideContent: {
532-
dynamicTabs: [],
533-
alerts: []
534-
}
526+
debuggerContext: {} as DebuggerContext
535527
});
536528

537529
export const defaultFileSystem: FileSystemState = {

src/commons/mocks/ContextMocks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export function mockRuntimeContext(): Context {
3737
control: null,
3838
stash: null,
3939
envStepsTotal: 0,
40-
breakpointSteps: []
40+
breakpointSteps: [],
41+
changepointSteps: []
4142
};
4243
return context;
4344
}

src/commons/sideContent/SideContentHelper.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,30 @@ const requireProvider = (x: string) => {
4545
return exports[x];
4646
};
4747

48-
type RawTab = (provider: ReturnType<typeof requireProvider>) => ModuleSideContent;
48+
type RawTab = (provider: ReturnType<typeof requireProvider>) => { default: ModuleSideContent };
4949

5050
/**
5151
* Returns an array of SideContentTabs to be spawned
5252
* @param debuggerContext - DebuggerContext object from redux store
5353
*/
54-
export const getDynamicTabs = (debuggerContext: DebuggerContext): SideContentTab[] => {
54+
export function getDynamicTabs(debuggerContext: DebuggerContext): SideContentTab[] {
5555
const moduleContexts = debuggerContext?.context?.moduleContexts;
5656

5757
if (!moduleContexts) return [];
5858

5959
return Object.values(moduleContexts)
6060
.flatMap(({ tabs }) => tabs ?? [])
61-
.map((rawTab: RawTab) => rawTab(requireProvider))
61+
.map((rawTab: RawTab) => {
62+
const { default: content } = rawTab(requireProvider);
63+
return content;
64+
})
6265
.filter(({ toSpawn }) => !toSpawn || toSpawn(debuggerContext))
6366
.map(tab => ({
6467
...tab,
6568
body: tab.body(debuggerContext),
6669
id: SideContentType.module
6770
}));
68-
};
71+
}
6972

7073
export const generateIconId = (tabId: TabId) => `${tabId}-icon`;
7174
export const getTabId = (tab: SideContentTab) =>

src/commons/sideContent/SideContentReducer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import { defaultSideContent, defaultSideContentManager } from '../application/Ap
22
import { SourceActionType } from '../utils/ActionsHelper';
33
import { getDynamicTabs, getTabId } from './SideContentHelper';
44
import { getLocation } from './SideContentHelper';
5-
import { CHANGE_SIDE_CONTENT_HEIGHT } from './SideContentTypes';
5+
import { CHANGE_SIDE_CONTENT_HEIGHT, SPAWN_SIDE_CONTENT } from './SideContentTypes';
66
import {
77
END_ALERT_SIDE_CONTENT,
88
REMOVE_SIDE_CONTENT_ALERT,
99
RESET_SIDE_CONTENT,
1010
SideContentManagerState,
11-
SPAWN_SIDE_CONTENT,
1211
VISIT_SIDE_CONTENT
1312
} from './SideContentTypes';
1413

src/commons/workspace/WorkspaceTypes.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { InterpreterOutput } from '../application/ApplicationTypes';
66
import { ExternalLibraryName } from '../application/types/ExternalTypes';
77
import { AutogradingResult, Testcase } from '../assessment/AssessmentTypes';
88
import { HighlightedLines, Position } from '../editor/EditorTypes';
9-
import { SideContentState } from '../sideContent/SideContentTypes';
109

1110
export const ADD_HTML_CONSOLE_ERROR = 'ADD_HTML_CONSOLE_ERROR';
1211
export const BEGIN_CLEAR_CONTEXT = 'BEGIN_CLEAR_CONTEXT';
@@ -147,7 +146,6 @@ export type WorkspaceState = {
147146
readonly stepLimit: number;
148147
readonly globals: Array<[string, any]>;
149148
readonly debuggerContext: DebuggerContext;
150-
readonly sideContent: SideContentState;
151149
readonly lastDebuggerResult: any;
152150
readonly lastNonDetResult: Result | null;
153151
};

src/features/cseMachine/CseMachineUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
UnOpInstr
1111
} from 'js-slang/dist/cse-machine/types';
1212
import { Environment, Value as StashValue } from 'js-slang/dist/types';
13-
import { astToString } from 'js-slang/dist/utils/astToString';
13+
import { astToString } from 'js-slang/dist/utils/ast/astToString';
1414
import { Group } from 'konva/lib/Group';
1515
import { Node } from 'konva/lib/Node';
1616
import { Shape } from 'konva/lib/Shape';

src/features/stories/StoriesTypes.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Context } from 'js-slang';
2-
import { SideContentState } from 'src/commons/sideContent/SideContentTypes';
32
import { DebuggerContext } from 'src/commons/workspace/WorkspaceTypes';
43

54
import { InterpreterOutput, StoriesRole } from '../../commons/application/ApplicationTypes';
@@ -60,7 +59,6 @@ export type StoriesEnvState = {
6059
readonly globals: Array<[string, any]>;
6160
readonly usingSubst: boolean;
6261
readonly debuggerContext: DebuggerContext;
63-
readonly sideContent: SideContentState;
6462
};
6563

6664
export type StoriesAuthState = {

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'src/styles/index.scss';
22

33
import { Button } from '@blueprintjs/core';
44
import * as Sentry from '@sentry/browser';
5-
import { setModulesStaticURL } from 'js-slang/dist/modules/moduleLoader';
5+
import { setModulesStaticURL } from 'js-slang/dist/modules/loader/moduleLoader';
66
import { createRoot } from 'react-dom/client';
77
import { Provider } from 'react-redux';
88
import Constants, { Links } from 'src/commons/utils/Constants';

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8305,10 +8305,10 @@ js-sdsl@4.3.0, js-sdsl@^4.1.4:
83058305
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.3.0.tgz#aeefe32a451f7af88425b11fdb5f58c90ae1d711"
83068306
integrity sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==
83078307

8308-
js-slang@^1.0.51:
8309-
version "1.0.51"
8310-
resolved "https://registry.yarnpkg.com/js-slang/-/js-slang-1.0.51.tgz#254ec52f4db29a8f51276cf681cf2608698337cf"
8311-
integrity sha512-UmoWDfcgwxG86s+Q7y9BxU8PcPnyyTs6jgVK77luaGqMy+kDKwwNqajjIOmd3thVOouAj2U1llAjVT1oZtmCLw==
8308+
js-slang@^1.0.52:
8309+
version "1.0.52"
8310+
resolved "https://registry.yarnpkg.com/js-slang/-/js-slang-1.0.52.tgz#f24d504e09842fc6567789b45e8c9fc3a86a38d3"
8311+
integrity sha512-Ioe/XQFxAwZpDGNsg8MDKbC/0CvLXN+0mwhKrtm2jq6PHGa9oldZqykZZAlPYdC5XifI3DktKrRmuc94AIiKfA==
83128312
dependencies:
83138313
"@babel/parser" "^7.19.4"
83148314
"@joeychenofficial/alt-ergo-modified" "^2.4.0"

0 commit comments

Comments
 (0)