Skip to content

Commit 535baf3

Browse files
committed
Migrate BROWSE_REPL_HISTORY_UP to new reducer
1 parent a5011ba commit 535baf3

File tree

1 file changed

+31
-45
lines changed

1 file changed

+31
-45
lines changed

src/commons/workspace/WorkspaceReducer.ts

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ import { NOTIFY_PROGRAM_EVALUATED } from '../sideContent/SideContentTypes';
3333
import { SourceActionType } from '../utils/ActionsHelper';
3434
import Constants from '../utils/Constants';
3535
import { createContext } from '../utils/JsSlangHelper';
36-
import { browseReplHistoryDown } from './WorkspaceActions';
36+
import { browseReplHistoryDown, browseReplHistoryUp } from './WorkspaceActions';
3737
import {
3838
ADD_EDITOR_TAB,
39-
BROWSE_REPL_HISTORY_UP,
4039
CHANGE_EXEC_TIME,
4140
CHANGE_EXTERNAL_LIBRARY,
4241
CHANGE_SIDE_CONTENT_HEIGHT,
@@ -128,7 +127,6 @@ export const WorkspaceReducer: Reducer<WorkspaceManagerState> = (
128127

129128
const newWorkspaceReducer = createReducer(defaultWorkspaceManager, builder => {
130129
builder
131-
.addCase('TODO: REMOVE INDENTATION FIX', (state, action) => {})
132130
.addCase(browseReplHistoryDown, (state, action) => {
133131
const workspaceLocation = getWorkspaceLocation(action);
134132
if (state[workspaceLocation].replHistory.browseIndex === null) {
@@ -156,62 +154,50 @@ const newWorkspaceReducer = createReducer(defaultWorkspaceManager, builder => {
156154
records: newRecords,
157155
originalValue: ''
158156
};
159-
});
160-
});
161-
162-
const oldWorkspaceReducer: Reducer<WorkspaceManagerState> = (
163-
state = defaultWorkspaceManager,
164-
action: SourceActionType
165-
) => {
166-
const workspaceLocation = getWorkspaceLocation(action);
167-
let newOutput: InterpreterOutput[];
168-
let lastOutput: InterpreterOutput;
169-
170-
switch (action.type) {
171-
case BROWSE_REPL_HISTORY_UP:
157+
})
158+
.addCase(browseReplHistoryUp, (state, action) => {
159+
const workspaceLocation = getWorkspaceLocation(action);
172160
const lastRecords = state[workspaceLocation].replHistory.records;
173161
const lastIndex = state[workspaceLocation].replHistory.browseIndex;
174162
if (
175163
lastRecords.length === 0 ||
176164
(lastIndex !== null && lastRecords[lastIndex + 1] === undefined)
177165
) {
178166
// There is no more later history to show
179-
return state;
180-
} else if (lastIndex === null) {
167+
return;
168+
}
169+
if (lastIndex === null) {
181170
// Not yet started browsing, initialise the index & array
182171
const newIndex = 0;
183172
const newRecords = lastRecords.slice();
184173
const originalValue = state[workspaceLocation].replValue;
185174
const newReplValue = newRecords[newIndex];
186-
return {
187-
...state,
188-
[workspaceLocation]: {
189-
...state[workspaceLocation],
190-
replValue: newReplValue,
191-
replHistory: {
192-
...state[workspaceLocation].replHistory,
193-
browseIndex: newIndex,
194-
records: newRecords,
195-
originalValue
196-
}
197-
}
198-
};
199-
} else {
200-
// Browsing history, and still have later history to show
201-
const newIndex = lastIndex + 1;
202-
const newReplValue = lastRecords[newIndex];
203-
return {
204-
...state,
205-
[workspaceLocation]: {
206-
...state[workspaceLocation],
207-
replValue: newReplValue,
208-
replHistory: {
209-
...state[workspaceLocation].replHistory,
210-
browseIndex: newIndex
211-
}
212-
}
175+
176+
state[workspaceLocation].replValue = newReplValue;
177+
state[workspaceLocation].replHistory = {
178+
browseIndex: newIndex,
179+
records: newRecords,
180+
originalValue
213181
};
182+
return;
214183
}
184+
// Browsing history, and still have later history to show
185+
const newIndex = lastIndex + 1;
186+
const newReplValue = lastRecords[newIndex];
187+
state[workspaceLocation].replValue = newReplValue;
188+
state[workspaceLocation].replHistory.browseIndex = newIndex;
189+
});
190+
});
191+
192+
const oldWorkspaceReducer: Reducer<WorkspaceManagerState> = (
193+
state = defaultWorkspaceManager,
194+
action: SourceActionType
195+
) => {
196+
const workspaceLocation = getWorkspaceLocation(action);
197+
let newOutput: InterpreterOutput[];
198+
let lastOutput: InterpreterOutput;
199+
200+
switch (action.type) {
215201
case CHANGE_EXEC_TIME:
216202
return {
217203
...state,

0 commit comments

Comments
 (0)