diff --git a/src/commons/sagas/MainSaga.ts b/src/commons/sagas/MainSaga.ts index 61d87a381a..ed9ec1e3f0 100644 --- a/src/commons/sagas/MainSaga.ts +++ b/src/commons/sagas/MainSaga.ts @@ -1,5 +1,5 @@ import { SagaIterator } from 'redux-saga'; -import { fork } from 'redux-saga/effects'; +import { all, fork } from 'redux-saga/effects'; import { mockBackendSaga } from '../mocks/BackendMocks'; import Constants from '../utils/Constants'; @@ -15,14 +15,16 @@ import StoriesSaga from './StoriesSaga'; import WorkspaceSaga from './WorkspaceSaga'; export default function* MainSaga(): SagaIterator { - yield fork(Constants.useBackend ? BackendSaga : mockBackendSaga); - yield fork(WorkspaceSaga); - yield fork(LoginSaga); - yield fork(PlaygroundSaga); - yield fork(AchievementSaga); - yield fork(PersistenceSaga); - yield fork(GitHubPersistenceSaga); - yield fork(RemoteExecutionSaga); - yield fork(StoriesSaga); - yield fork(SideContentSaga); + yield all([ + fork(Constants.useBackend ? BackendSaga : mockBackendSaga), + fork(WorkspaceSaga), + fork(LoginSaga), + fork(PlaygroundSaga), + fork(AchievementSaga), + fork(PersistenceSaga), + fork(GitHubPersistenceSaga), + fork(RemoteExecutionSaga), + fork(StoriesSaga), + fork(SideContentSaga) + ]); } diff --git a/src/commons/workspace/WorkspaceActions.ts b/src/commons/workspace/WorkspaceActions.ts index ad4f8df915..dd7e5c5de6 100644 --- a/src/commons/workspace/WorkspaceActions.ts +++ b/src/commons/workspace/WorkspaceActions.ts @@ -93,7 +93,7 @@ export const browseReplHistoryUp = createAction( export const changeExternalLibrary = createAction( CHANGE_EXTERNAL_LIBRARY, - (newExternal: string, workspaceLocation: WorkspaceLocation) => ({ + (newExternal: ExternalLibraryName, workspaceLocation: WorkspaceLocation) => ({ payload: { newExternal, workspaceLocation } }) ); diff --git a/src/commons/workspace/WorkspaceReducer.ts b/src/commons/workspace/WorkspaceReducer.ts index b91362b3cd..47c3f4251c 100644 --- a/src/commons/workspace/WorkspaceReducer.ts +++ b/src/commons/workspace/WorkspaceReducer.ts @@ -1,3 +1,4 @@ +import { createReducer } from '@reduxjs/toolkit'; import { stringify } from 'js-slang/dist/utils/stringify'; import { Reducer } from 'redux'; @@ -33,16 +34,19 @@ import { NOTIFY_PROGRAM_EVALUATED } from '../sideContent/SideContentTypes'; import { SourceActionType } from '../utils/ActionsHelper'; import Constants from '../utils/Constants'; import { createContext } from '../utils/JsSlangHelper'; +import { + browseReplHistoryDown, + browseReplHistoryUp, + changeExecTime, + changeStepLimit, + clearReplInput, + clearReplOutput, + clearReplOutputLast, + setTokenCount +} from './WorkspaceActions'; import { ADD_EDITOR_TAB, - BROWSE_REPL_HISTORY_DOWN, - BROWSE_REPL_HISTORY_UP, - CHANGE_EXEC_TIME, CHANGE_EXTERNAL_LIBRARY, - CHANGE_STEP_LIMIT, - CLEAR_REPL_INPUT, - CLEAR_REPL_OUTPUT, - CLEAR_REPL_OUTPUT_LAST, DISABLE_TOKEN_COUNTER, EditorTabState, ENABLE_TOKEN_COUNTER, @@ -59,7 +63,6 @@ import { RESET_WORKSPACE, SEND_REPL_INPUT_TO_OUTPUT, SET_FOLDER_MODE, - SET_TOKEN_COUNT, SHIFT_EDITOR_TAB, TOGGLE_EDITOR_AUTORUN, TOGGLE_UPDATE_ENV, @@ -83,6 +86,10 @@ import { WorkspaceManagerState } from './WorkspaceTypes'; +const getWorkspaceLocation = (action: any): WorkspaceLocation => { + return action.payload ? action.payload.workspaceLocation : 'assessment'; +}; + /** * Takes in a IWorkspaceManagerState and maps it to a new state. The * pre-conditions are that @@ -95,12 +102,7 @@ export const WorkspaceReducer: Reducer = ( state = defaultWorkspaceManager, action: SourceActionType ) => { - const workspaceLocation: WorkspaceLocation = (action as any).payload - ? (action as any).payload.workspaceLocation - : 'assessment'; - let newOutput: InterpreterOutput[]; - let lastOutput: InterpreterOutput; - + const workspaceLocation = getWorkspaceLocation(action); switch (workspaceLocation) { case 'sourcecast': const sourcecastState = SourcecastReducer(state.sourcecast, action); @@ -124,55 +126,47 @@ export const WorkspaceReducer: Reducer = ( break; } - switch (action.type) { - case SET_TOKEN_COUNT: - return { - ...state, - [workspaceLocation]: { - ...state[workspaceLocation], - tokenCount: action.payload.tokenCount - } - }; + state = oldWorkspaceReducer(state, action); + state = newWorkspaceReducer(state, action); + return state; +}; - case BROWSE_REPL_HISTORY_DOWN: +const newWorkspaceReducer = createReducer(defaultWorkspaceManager, builder => { + builder + .addCase(setTokenCount, (state, action) => { + const workspaceLocation = getWorkspaceLocation(action); + state[workspaceLocation].tokenCount = action.payload.tokenCount; + }) + .addCase(browseReplHistoryDown, (state, action) => { + const workspaceLocation = getWorkspaceLocation(action); if (state[workspaceLocation].replHistory.browseIndex === null) { // Not yet started browsing history, nothing to do - return state; - } else if (state[workspaceLocation].replHistory.browseIndex !== 0) { + return; + } + if (state[workspaceLocation].replHistory.browseIndex !== 0) { // Browsing history, and still have earlier records to show const newIndex = state[workspaceLocation].replHistory.browseIndex! - 1; const newReplValue = state[workspaceLocation].replHistory.records[newIndex]; - return { - ...state, - [workspaceLocation]: { - ...state[workspaceLocation], - replValue: newReplValue, - replHistory: { - ...state[workspaceLocation].replHistory, - browseIndex: newIndex - } - } - }; - } else { - // Browsing history, no earlier records to show; return replValue to - // the last value when user started browsing - const newIndex = null; - const newReplValue = state[workspaceLocation].replHistory.originalValue; - const newRecords = state[workspaceLocation].replHistory.records.slice(); - return { - ...state, - [workspaceLocation]: { - ...state[workspaceLocation], - replValue: newReplValue, - replHistory: { - browseIndex: newIndex, - records: newRecords, - originalValue: '' - } - } - }; + + state[workspaceLocation].replValue = newReplValue; + state[workspaceLocation].replHistory.browseIndex = newIndex; + return; } - case BROWSE_REPL_HISTORY_UP: + // Browsing history, no earlier records to show; return replValue to + // the last value when user started browsing + const newIndex = null; + const newReplValue = state[workspaceLocation].replHistory.originalValue; + const newRecords = state[workspaceLocation].replHistory.records.slice(); + + state[workspaceLocation].replValue = newReplValue; + state[workspaceLocation].replHistory = { + browseIndex: newIndex, + records: newRecords, + originalValue: '' + }; + }) + .addCase(browseReplHistoryUp, (state, action) => { + const workspaceLocation = getWorkspaceLocation(action); const lastRecords = state[workspaceLocation].replHistory.records; const lastIndex = state[workspaceLocation].replHistory.browseIndex; if ( @@ -180,82 +174,60 @@ export const WorkspaceReducer: Reducer = ( (lastIndex !== null && lastRecords[lastIndex + 1] === undefined) ) { // There is no more later history to show - return state; - } else if (lastIndex === null) { + return; + } + if (lastIndex === null) { // Not yet started browsing, initialise the index & array const newIndex = 0; const newRecords = lastRecords.slice(); const originalValue = state[workspaceLocation].replValue; const newReplValue = newRecords[newIndex]; - return { - ...state, - [workspaceLocation]: { - ...state[workspaceLocation], - replValue: newReplValue, - replHistory: { - ...state[workspaceLocation].replHistory, - browseIndex: newIndex, - records: newRecords, - originalValue - } - } - }; - } else { - // Browsing history, and still have later history to show - const newIndex = lastIndex + 1; - const newReplValue = lastRecords[newIndex]; - return { - ...state, - [workspaceLocation]: { - ...state[workspaceLocation], - replValue: newReplValue, - replHistory: { - ...state[workspaceLocation].replHistory, - browseIndex: newIndex - } - } + + state[workspaceLocation].replValue = newReplValue; + state[workspaceLocation].replHistory = { + browseIndex: newIndex, + records: newRecords, + originalValue }; + return; } - case CHANGE_EXEC_TIME: - return { - ...state, - [workspaceLocation]: { - ...state[workspaceLocation], - execTime: action.payload.execTime - } - }; - case CHANGE_STEP_LIMIT: - return { - ...state, - [workspaceLocation]: { - ...state[workspaceLocation], - stepLimit: action.payload.stepLimit - } - }; - case CLEAR_REPL_INPUT: - return { - ...state, - [workspaceLocation]: { - ...state[workspaceLocation], - replValue: '' - } - }; - case CLEAR_REPL_OUTPUT_LAST: - return { - ...state, - [workspaceLocation]: { - ...state[workspaceLocation], - output: state[workspaceLocation].output.slice(0, -1) - } - }; - case CLEAR_REPL_OUTPUT: - return { - ...state, - [workspaceLocation]: { - ...state[workspaceLocation], - output: [] - } - }; + // Browsing history, and still have later history to show + const newIndex = lastIndex + 1; + const newReplValue = lastRecords[newIndex]; + state[workspaceLocation].replValue = newReplValue; + state[workspaceLocation].replHistory.browseIndex = newIndex; + }) + .addCase(changeExecTime, (state, action) => { + const workspaceLocation = getWorkspaceLocation(action); + state[workspaceLocation].execTime = action.payload.execTime; + }) + .addCase(changeStepLimit, (state, action) => { + const workspaceLocation = getWorkspaceLocation(action); + state[workspaceLocation].stepLimit = action.payload.stepLimit; + }) + .addCase(clearReplInput, (state, action) => { + const workspaceLocation = getWorkspaceLocation(action); + state[workspaceLocation].replValue = ''; + }) + .addCase(clearReplOutputLast, (state, action) => { + const workspaceLocation = getWorkspaceLocation(action); + state[workspaceLocation].output.pop(); + }) + .addCase(clearReplOutput, (state, action) => { + const workspaceLocation = getWorkspaceLocation(action); + state[workspaceLocation].output = []; + }); +}); + +const oldWorkspaceReducer: Reducer = ( + state = defaultWorkspaceManager, + action: SourceActionType +) => { + const workspaceLocation = getWorkspaceLocation(action); + let newOutput: InterpreterOutput[]; + let lastOutput: InterpreterOutput; + + switch (action.type) { case END_CLEAR_CONTEXT: return { ...state, diff --git a/src/commons/workspace/__tests__/WorkspaceActions.ts b/src/commons/workspace/__tests__/WorkspaceActions.ts index 4055cfa2c0..d9616a502d 100644 --- a/src/commons/workspace/__tests__/WorkspaceActions.ts +++ b/src/commons/workspace/__tests__/WorkspaceActions.ts @@ -120,7 +120,7 @@ test('browseReplHistoryUp generates correct action object', () => { }); test('changeExternalLibrary generates correct action object', () => { - const newExternal = 'new-external-test'; + const newExternal = 'new-external-test' as ExternalLibraryName; const action = changeExternalLibrary(newExternal, playgroundWorkspace); expect(action).toEqual({ type: CHANGE_EXTERNAL_LIBRARY, diff --git a/src/commons/workspace/__tests__/WorkspaceReducer.ts b/src/commons/workspace/__tests__/WorkspaceReducer.ts index f58d871ec9..04afe617cc 100644 --- a/src/commons/workspace/__tests__/WorkspaceReducer.ts +++ b/src/commons/workspace/__tests__/WorkspaceReducer.ts @@ -69,66 +69,20 @@ import { WorkspaceManagerState } from '../WorkspaceTypes'; -const assessmentWorkspace: WorkspaceLocation = 'assessment'; -const gradingWorkspace: WorkspaceLocation = 'grading'; const playgroundWorkspace: WorkspaceLocation = 'playground'; -const sourcecastWorkspace: WorkspaceLocation = 'sourcecast'; -const sourcereelWorkspace: WorkspaceLocation = 'sourcereel'; const sicpWorkspace: WorkspaceLocation = 'sicp'; -const githubAssessmentWorkspace: WorkspaceLocation = 'githubAssessment'; +const locations: ReadonlyArray = [ + 'assessment', + 'grading', + 'playground', + 'sourcecast', + 'sourcereel', + 'sicp', + 'githubAssessment' +] as const; function generateActions(type: string, payload: any = {}): any[] { - return [ - { - type, - payload: { - ...payload, - workspaceLocation: assessmentWorkspace - } - }, - { - type, - payload: { - ...payload, - workspaceLocation: gradingWorkspace - } - }, - { - type, - payload: { - ...payload, - workspaceLocation: playgroundWorkspace - } - }, - { - type, - payload: { - ...payload, - workspaceLocation: sourcecastWorkspace - } - }, - { - type, - payload: { - ...payload, - workspaceLocation: sourcereelWorkspace - } - }, - { - type, - payload: { - ...payload, - workspaceLocation: sicpWorkspace - } - }, - { - type, - payload: { - ...payload, - workspaceLocation: githubAssessmentWorkspace - } - } - ]; + return locations.map(l => ({ type, payload: { ...payload, workspaceLocation: l } })); } // cloneDeep not required for proper redux @@ -345,12 +299,7 @@ describe('CLEAR_REPL_INPUT', () => { describe('CLEAR_REPL_OUTPUT', () => { test('clears output', () => { - const output: InterpreterOutput[] = [ - { - type: 'code', - value: 'test repl input' - } - ]; + const output: InterpreterOutput[] = [{ type: 'code', value: 'test repl input' }]; const clearReplDefaultState: WorkspaceManagerState = generateDefaultWorkspace({ output }); const actions = generateActions(CLEAR_REPL_OUTPUT); @@ -568,25 +517,13 @@ describe('EVAL_EDITOR', () => { // Test data for EVAL_INTERPRETER_ERROR, EVAL_INTERPRETER_SUCCESS, EVAL_TESTCASE_SUCCESS and HANDLE_CONSOLE_OUTPUT const outputWithRunningOutput: RunningOutput[] = [ - { - type: 'running', - consoleLogs: ['console-log-test'] - }, - { - type: 'running', - consoleLogs: ['console-log-test-2'] - } + { type: 'running', consoleLogs: ['console-log-test'] }, + { type: 'running', consoleLogs: ['console-log-test-2'] } ]; const outputWithRunningAndCodeOutput: InterpreterOutput[] = [ - { - type: 'running', - consoleLogs: ['console-log-test'] - }, - { - type: 'code', - value: 'sample code' - } + { type: 'running', consoleLogs: ['console-log-test'] }, + { type: 'code', value: 'sample code' } ]; describe('EVAL_INTERPRETER_ERROR', () => { @@ -610,14 +547,7 @@ describe('EVAL_INTERPRETER_ERROR', () => { ...evalEditorDefaultState[location], isRunning: false, isDebugging: false, - output: [ - { - ...outputWithRunningOutput[0] - }, - { - consoleLogs: ['console-log-test-2'] - } - ] + output: [{ ...outputWithRunningOutput[0] }, { consoleLogs: ['console-log-test-2'] }] } }); }); @@ -644,15 +574,9 @@ describe('EVAL_INTERPRETER_ERROR', () => { isRunning: false, isDebugging: false, output: [ - { - ...outputWithRunningAndCodeOutput[0] - }, - { - ...outputWithRunningAndCodeOutput[1] - }, - { - consoleLogs: [] - } + { ...outputWithRunningAndCodeOutput[0] }, + { ...outputWithRunningAndCodeOutput[1] }, + { consoleLogs: [] } ] } }); @@ -683,13 +607,8 @@ describe('EVAL_INTERPRETER_SUCCESS', () => { ...evalEditorDefaultState[location], isRunning: false, output: [ - { - ...outputWithRunningOutput[0] - }, - { - consoleLogs: ['console-log-test-2'], - value: 'undefined' - } + { ...outputWithRunningOutput[0] }, + { consoleLogs: ['console-log-test-2'], value: 'undefined' } ] } }); @@ -718,16 +637,9 @@ describe('EVAL_INTERPRETER_SUCCESS', () => { ...evalEditorDefaultState[location], isRunning: false, output: [ - { - ...outputWithRunningAndCodeOutput[0] - }, - { - ...outputWithRunningAndCodeOutput[1] - }, - { - consoleLogs: [], - value: 'undefined' - } + { ...outputWithRunningAndCodeOutput[0] }, + { ...outputWithRunningAndCodeOutput[1] }, + { consoleLogs: [], value: 'undefined' } ] } }); @@ -755,25 +667,13 @@ describe('EVAL_REPL', () => { // Test data for EVAL_TESTCASE_FAILURE and EVAL_TESTCASE_SUCCESS const outputWithCodeAndRunningOutput: InterpreterOutput[] = [ - { - type: 'code', - value: 'sample code' - }, - { - type: 'running', - consoleLogs: ['console-log-test'] - } + { type: 'code', value: 'sample code' }, + { type: 'running', consoleLogs: ['console-log-test'] } ]; const outputWithCodeOutput: CodeOutput[] = [ - { - type: 'code', - value: 'code 1' - }, - { - type: 'code', - value: 'code 2' - } + { type: 'code', value: 'code 1' }, + { type: 'code', value: 'code 2' } ]; const editorTestcases: Testcase[] = [ @@ -797,10 +697,7 @@ describe('EVAL_TESTCASE_FAILURE', () => { const evalFailureDefaultState: WorkspaceManagerState = generateDefaultWorkspace({ editorTestcases }); - const actions = generateActions(EVAL_TESTCASE_FAILURE, { - value, - index: 1 - }); + const actions = generateActions(EVAL_TESTCASE_FAILURE, { value, index: 1 }); actions.forEach(action => { const result = WorkspaceReducer(evalFailureDefaultState, action); @@ -810,14 +707,8 @@ describe('EVAL_TESTCASE_FAILURE', () => { [location]: { ...evalFailureDefaultState[location], editorTestcases: [ - { - ...editorTestcases[0] - }, - { - ...editorTestcases[1], - result: undefined, - errors: value - } + { ...editorTestcases[0] }, + { ...editorTestcases[1], result: undefined, errors: value } ] } }); @@ -835,10 +726,7 @@ describe('EVAL_TESTCASE_SUCCESS', () => { editorTestcases }); - const actions = generateActions(EVAL_TESTCASE_SUCCESS, { - value, - index: 1 - }); + const actions = generateActions(EVAL_TESTCASE_SUCCESS, { value, index: 1 }); actions.forEach(action => { const result = WorkspaceReducer(testcaseSuccessDefaultState, action); @@ -850,14 +738,8 @@ describe('EVAL_TESTCASE_SUCCESS', () => { isRunning: false, output: outputWithCodeAndRunningOutput, editorTestcases: [ - { - ...editorTestcases[0] - }, - { - ...editorTestcases[1], - result: value, - errors: undefined - } + { ...editorTestcases[0] }, + { ...editorTestcases[1], result: value, errors: undefined } ] } }); @@ -873,10 +755,7 @@ describe('EVAL_TESTCASE_SUCCESS', () => { editorTestcases }); - const actions = generateActions(EVAL_TESTCASE_SUCCESS, { - value, - index: 0 - }); + const actions = generateActions(EVAL_TESTCASE_SUCCESS, { value, index: 0 }); actions.forEach(action => { const result = WorkspaceReducer(testcaseSuccessDefaultState, action); @@ -888,14 +767,8 @@ describe('EVAL_TESTCASE_SUCCESS', () => { isRunning: false, output: outputWithCodeOutput, editorTestcases: [ - { - ...editorTestcases[0], - result: value, - errors: undefined - }, - { - ...editorTestcases[1] - } + { ...editorTestcases[0], result: value, errors: undefined }, + { ...editorTestcases[1] } ] } }); @@ -917,9 +790,7 @@ describe('HANDLE_CONSOLE_LOG', () => { [location]: { ...consoleLogDefaultState[location], output: [ - { - ...outputWithRunningOutput[0] - }, + { ...outputWithRunningOutput[0] }, { ...outputWithRunningOutput[1], consoleLogs: outputWithRunningOutput[1].consoleLogs.concat(logString) @@ -966,12 +837,7 @@ describe('HANDLE_CONSOLE_LOG', () => { ...consoleLogDefaultState, [location]: { ...consoleLogDefaultState[location], - output: [ - { - type: 'running', - consoleLogs: [logString] - } - ] + output: [{ type: 'running', consoleLogs: [logString] }] } }); }); @@ -1039,14 +905,8 @@ describe('RESET_TESTCASE', () => { [location]: { ...resetTestcaseDefaultState[location], editorTestcases: [ - { - ...editorTestcases[0] - }, - { - ...editorTestcases[1], - result: undefined, - errors: undefined - } + { ...editorTestcases[0] }, + { ...editorTestcases[1], result: undefined, errors: undefined } ] } }); @@ -1144,10 +1004,7 @@ describe('SEND_REPL_INPUT_TO_OUTPUT', () => { }); const newOutput = ''; - const actions = generateActions(SEND_REPL_INPUT_TO_OUTPUT, { - type: 'code', - value: newOutput - }); + const actions = generateActions(SEND_REPL_INPUT_TO_OUTPUT, { type: 'code', value: newOutput }); actions.forEach(action => { const result = WorkspaceReducer(inputToOutputDefaultState, action); @@ -1156,13 +1013,7 @@ describe('SEND_REPL_INPUT_TO_OUTPUT', () => { ...inputToOutputDefaultState, [location]: { ...inputToOutputDefaultState[location], - output: [ - { - type: 'code', - workspaceLocation: location, - value: newOutput - } - ], + output: [{ type: 'code', workspaceLocation: location, value: newOutput }], replHistory } }); @@ -1241,10 +1092,7 @@ describe('UPDATE_CURRENT_ASSESSMENT_ID', () => { const questionId = 7; const assessmentAction = { type: UPDATE_CURRENT_ASSESSMENT_ID, - payload: { - assessmentId, - questionId - } + payload: { assessmentId, questionId } }; const result = WorkspaceReducer(defaultWorkspaceManager, assessmentAction); @@ -1265,10 +1113,7 @@ describe('UPDATE_CURRENT_SUBMISSION_ID', () => { const questionId = 8; const assessmentAction = { type: UPDATE_CURRENT_SUBMISSION_ID, - payload: { - submissionId, - questionId - } + payload: { submissionId, questionId } }; const result = WorkspaceReducer(defaultWorkspaceManager, assessmentAction); @@ -1505,13 +1350,7 @@ describe('UPDATE_EDITOR_VALUE', () => { ...defaultWorkspaceState, [location]: { ...defaultWorkspaceState[location], - editorTabs: [ - zerothEditorTab, - { - ...firstEditorTab, - value: newEditorValue - } - ] + editorTabs: [zerothEditorTab, { ...firstEditorTab, value: newEditorValue }] } }); }); @@ -1578,13 +1417,7 @@ describe('UPDATE_EDITOR_BREAKPOINTS', () => { ...defaultWorkspaceState, [location]: { ...defaultWorkspaceState[location], - editorTabs: [ - zerothEditorTab, - { - ...firstEditorTab, - breakpoints: newBreakpoints - } - ] + editorTabs: [zerothEditorTab, { ...firstEditorTab, breakpoints: newBreakpoints }] } }); }); @@ -1665,10 +1498,7 @@ describe('UPDATE_EDITOR_HIGHLIGHTED_LINES', () => { ...defaultWorkspaceState[location], editorTabs: [ zerothEditorTab, - { - ...firstEditorTab, - highlightedLines: newHighlightedLines - } + { ...firstEditorTab, highlightedLines: newHighlightedLines } ] } }); @@ -1748,13 +1578,7 @@ describe('MOVE_CURSOR', () => { ...defaultWorkspaceState, [location]: { ...defaultWorkspaceState[location], - editorTabs: [ - zerothEditorTab, - { - ...firstEditorTab, - newCursorPosition - } - ] + editorTabs: [zerothEditorTab, { ...firstEditorTab, newCursorPosition }] } }); }); @@ -1800,12 +1624,7 @@ describe('ADD_EDITOR_TAB', () => { editorTabs: [ zerothEditorTab, firstEditorTab, - { - filePath, - value: editorValue, - highlightedLines: [], - breakpoints: [] - } + { filePath, value: editorValue, highlightedLines: [], breakpoints: [] } ] } }) @@ -2593,13 +2412,7 @@ describe('RENAME_EDITOR_TAB_FOR_FILE', () => { ...defaultWorkspaceState, [location]: { ...defaultWorkspaceManager[location], - editorTabs: [ - zerothEditorTab, - { - ...firstEditorTab, - filePath: newFilePath - } - ] + editorTabs: [zerothEditorTab, { ...firstEditorTab, filePath: newFilePath }] } }) ); @@ -2740,9 +2553,7 @@ describe('TOGGLE_USING_SUBST', () => { usingSubst: true } } - : { - ...defaultWorkspaceManager - }; + : { ...defaultWorkspaceManager }; expect(result).toEqual(expectedResult); }); diff --git a/src/features/playground/PlaygroundActions.ts b/src/features/playground/PlaygroundActions.ts index 2be26fbf99..a43b0da19a 100644 --- a/src/features/playground/PlaygroundActions.ts +++ b/src/features/playground/PlaygroundActions.ts @@ -1,3 +1,4 @@ +import { createAction } from '@reduxjs/toolkit'; import { SALanguage } from 'src/commons/application/ApplicationTypes'; import { action } from 'typesafe-actions'; @@ -14,20 +15,29 @@ import { export const generateLzString = () => action(GENERATE_LZ_STRING); -export const shortenURL = (keyword: string) => action(SHORTEN_URL, keyword); +export const shortenURL = createAction(SHORTEN_URL, (keyword: string) => ({ payload: keyword })); -export const updateShortURL = (shortURL: string) => action(UPDATE_SHORT_URL, shortURL); +export const updateShortURL = createAction(UPDATE_SHORT_URL, (shortURL: string) => ({ + payload: shortURL +})); -export const changeQueryString = (queryString: string) => action(CHANGE_QUERY_STRING, queryString); +export const changeQueryString = createAction(CHANGE_QUERY_STRING, (queryString: string) => ({ + payload: queryString +})); -export const playgroundUpdatePersistenceFile = (file?: PersistenceFile) => - action(PLAYGROUND_UPDATE_PERSISTENCE_FILE, file); +export const playgroundUpdatePersistenceFile = createAction( + PLAYGROUND_UPDATE_PERSISTENCE_FILE, + (file?: PersistenceFile) => ({ payload: file }) +); -export const playgroundUpdateGitHubSaveInfo = ( - repoName: string, - filePath: string, - lastSaved: Date -) => action(PLAYGROUND_UPDATE_GITHUB_SAVE_INFO, { repoName, filePath, lastSaved }); +export const playgroundUpdateGitHubSaveInfo = createAction( + PLAYGROUND_UPDATE_GITHUB_SAVE_INFO, + (repoName: string, filePath: string, lastSaved: Date) => ({ + payload: { repoName, filePath, lastSaved } + }) +); -export const playgroundConfigLanguage = (languageConfig: SALanguage) => - action(PLAYGROUND_UPDATE_LANGUAGE_CONFIG, languageConfig); +export const playgroundConfigLanguage = createAction( + PLAYGROUND_UPDATE_LANGUAGE_CONFIG, + (languageConfig: SALanguage) => ({ payload: languageConfig }) +); diff --git a/src/features/sourceRecorder/sourcereel/SourcereelActions.ts b/src/features/sourceRecorder/sourcereel/SourcereelActions.ts index 64c84043f1..1238150cb1 100644 --- a/src/features/sourceRecorder/sourcereel/SourcereelActions.ts +++ b/src/features/sourceRecorder/sourcereel/SourcereelActions.ts @@ -1,4 +1,4 @@ -import { action } from 'typesafe-actions'; +import { createAction } from '@reduxjs/toolkit'; import { WorkspaceLocation } from '../../../commons/workspace/WorkspaceTypes'; import { Input, PlaybackData } from '../SourceRecorderTypes'; @@ -14,56 +14,51 @@ import { TIMER_STOP } from './SourcereelTypes'; -export const deleteSourcecastEntry = (id: number, workspaceLocation: WorkspaceLocation) => - action(DELETE_SOURCECAST_ENTRY, { - id, - workspaceLocation - }); +export const deleteSourcecastEntry = createAction( + DELETE_SOURCECAST_ENTRY, + (id: number, workspaceLocation: WorkspaceLocation) => ({ payload: { id, workspaceLocation } }) +); -export const recordInit = (initData: PlaybackData['init'], workspaceLocation: WorkspaceLocation) => - action(RECORD_INIT, { - initData, - workspaceLocation - }); +export const recordInit = createAction( + RECORD_INIT, + (initData: PlaybackData['init'], workspaceLocation: WorkspaceLocation) => ({ + payload: { initData, workspaceLocation } + }) +); -export const recordInput = (input: Input, workspaceLocation: WorkspaceLocation) => - action(RECORD_INPUT, { - input, - workspaceLocation - }); +export const recordInput = createAction( + RECORD_INPUT, + (input: Input, workspaceLocation: WorkspaceLocation) => ({ + payload: { input, workspaceLocation } + }) +); -export const resetInputs = (inputs: Input[], workspaceLocation: WorkspaceLocation) => - action(RESET_INPUTS, { - inputs, - workspaceLocation - }); +export const resetInputs = createAction( + RESET_INPUTS, + (inputs: Input[], workspaceLocation: WorkspaceLocation) => ({ + payload: { inputs, workspaceLocation } + }) +); -export const timerPause = (workspaceLocation: WorkspaceLocation) => - action(TIMER_PAUSE, { - timeNow: Date.now(), - workspaceLocation - }); +export const timerPause = createAction(TIMER_PAUSE, (workspaceLocation: WorkspaceLocation) => ({ + payload: { timeNow: Date.now(), workspaceLocation } +})); -export const timerReset = (workspaceLocation: WorkspaceLocation) => - action(TIMER_RESET, { - workspaceLocation - }); +export const timerReset = createAction(TIMER_RESET, (workspaceLocation: WorkspaceLocation) => ({ + payload: { workspaceLocation } +})); -export const timerResume = (timeBefore: number, workspaceLocation: WorkspaceLocation) => - action(TIMER_RESUME, { - timeBefore, - timeNow: Date.now(), - workspaceLocation - }); +export const timerResume = createAction( + TIMER_RESUME, + (timeBefore: number, workspaceLocation: WorkspaceLocation) => ({ + payload: { timeBefore, timeNow: Date.now(), workspaceLocation } + }) +); -export const timerStart = (workspaceLocation: WorkspaceLocation) => - action(TIMER_START, { - timeNow: Date.now(), - workspaceLocation - }); +export const timerStart = createAction(TIMER_START, (workspaceLocation: WorkspaceLocation) => ({ + payload: { timeNow: Date.now(), workspaceLocation } +})); -export const timerStop = (workspaceLocation: WorkspaceLocation) => - action(TIMER_STOP, { - timeNow: Date.now(), - workspaceLocation - }); +export const timerStop = createAction(TIMER_STOP, (workspaceLocation: WorkspaceLocation) => ({ + payload: { timeNow: Date.now(), workspaceLocation } +}));