Skip to content

Commit 9237602

Browse files
committed
Fix broken tsc
1 parent a953608 commit 9237602

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

src/commons/sagas/PlaygroundSaga.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { SideContentType } from '../sideContent/SideContentTypes';
1919
import Constants from '../utils/Constants';
2020
import { showSuccessMessage, showWarningMessage } from '../utils/notifications/NotificationsHelper';
2121
import WorkspaceActions from '../workspace/WorkspaceActions';
22-
import type { PlaygroundWorkspaceState } from '../workspace/WorkspaceTypes';
2322
import { safeTakeEvery as takeEvery, selectWorkspace } from './SafeEffects';
2423

2524
export default function* PlaygroundSaga(): SagaIterator {
@@ -77,9 +76,7 @@ export default function* PlaygroundSaga(): SagaIterator {
7776
const {
7877
context: { chapter: playgroundSourceChapter },
7978
editorTabs
80-
}: PlaygroundWorkspaceState = yield select(
81-
(state: OverallState) => state.workspaces[workspaceLocation]
82-
);
79+
} = yield* selectWorkspace('playground');
8380

8481
if (prevId === SideContentType.substVisualizer) {
8582
if (newId === SideContentType.mobileEditorRun) return;

src/commons/sagas/SafeEffects.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type ForkEffect,
66
type HelperWorkerParameters,
77
select,
8+
SelectEffect,
89
takeEvery,
910
takeLatest,
1011
takeLeading
@@ -101,10 +102,22 @@ export function safeTakeLeading<P extends ActionPattern, Fn extends (...args: an
101102
return takeLeading<P, typeof wrappedWorker>(pattern, wrappedWorker, ...args);
102103
}
103104

104-
export function* selectWorkspace<T extends WorkspaceLocation>(workspaceLocation: T) {
105+
export function selectWorkspace<T extends WorkspaceLocation, U>(
106+
workspaceLocation: T,
107+
func: (state: WorkspaceManagerState[T]) => U
108+
): Generator<SelectEffect, U>;
109+
export function selectWorkspace<T extends WorkspaceLocation>(
110+
workspaceLocation: T
111+
): Generator<SelectEffect, WorkspaceManagerState[T]>;
112+
export function* selectWorkspace<T extends WorkspaceLocation, U>(
113+
workspaceLocation: T,
114+
f?: (state: WorkspaceManagerState[T]) => U
115+
) {
105116
const workspace: WorkspaceManagerState[T] = yield select(
106117
(state: OverallState) => state.workspaces[workspaceLocation]
107118
);
119+
120+
if (f) return f(workspace);
108121
return workspace;
109122
}
110123

src/commons/sagas/__tests__/WorkspaceSaga.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ describe('DEBUG_RESUME', () => {
289289
editorValueFilePath,
290290
context,
291291
execTime,
292-
workspaceLocation,
293-
WorkspaceActions.evalEditor.type
292+
WorkspaceActions.evalEditor.type,
293+
workspaceLocation
294294
)
295295
.withState(state)
296296
.silentRun();
@@ -826,8 +826,8 @@ describe('evalCode', () => {
826826
codeFilePath,
827827
context,
828828
execTime,
829-
workspaceLocation,
830-
actionType
829+
actionType,
830+
workspaceLocation
831831
)
832832
.withState(state)
833833
.provide([
@@ -855,8 +855,8 @@ describe('evalCode', () => {
855855
codeFilePath,
856856
context,
857857
execTime,
858-
workspaceLocation,
859-
actionType
858+
actionType,
859+
workspaceLocation
860860
)
861861
.withState(state)
862862
.provide([
@@ -885,8 +885,8 @@ describe('evalCode', () => {
885885
codeFilePath,
886886
context,
887887
execTime,
888-
workspaceLocation,
889-
actionType
888+
actionType,
889+
workspaceLocation
890890
)
891891
.withState(state)
892892
.provide([
@@ -922,8 +922,8 @@ describe('evalCode', () => {
922922
codeFilePath,
923923
context,
924924
execTime,
925-
workspaceLocation,
926-
actionType
925+
actionType,
926+
workspaceLocation
927927
)
928928
.withState(state)
929929
.call(runFilesInContext, files, codeFilePath, context, {
@@ -948,8 +948,8 @@ describe('evalCode', () => {
948948
codeFilePath,
949949
context,
950950
execTime,
951-
workspaceLocation,
952-
WorkspaceActions.evalEditor.type
951+
WorkspaceActions.evalEditor.type,
952+
workspaceLocation
953953
)
954954
.withState(state)
955955
.silentRun();
@@ -964,8 +964,8 @@ describe('evalCode', () => {
964964
codeFilePath,
965965
context,
966966
execTime,
967-
workspaceLocation,
968-
actionType
967+
actionType,
968+
workspaceLocation
969969
)
970970
.withState(state)
971971
.provide([[call(resume, lastDebuggerResult), { status: 'finished', value }]])
@@ -983,8 +983,8 @@ describe('evalCode', () => {
983983
codeFilePath,
984984
context,
985985
execTime,
986-
workspaceLocation,
987-
actionType
986+
actionType,
987+
workspaceLocation
988988
)
989989
.withState(state)
990990
.provide([[call(resume, lastDebuggerResult), { status: 'suspended-cse-eval' }]])
@@ -1003,8 +1003,8 @@ describe('evalCode', () => {
10031003
codeFilePath,
10041004
context,
10051005
execTime,
1006-
workspaceLocation,
1007-
actionType
1006+
actionType,
1007+
workspaceLocation
10081008
)
10091009
.withState(state)
10101010
.call(resume, lastDebuggerResult)
@@ -1021,8 +1021,8 @@ describe('evalCode', () => {
10211021
codeFilePath,
10221022
context,
10231023
execTime,
1024-
workspaceLocation,
1025-
actionType
1024+
actionType,
1025+
workspaceLocation
10261026
)
10271027
.withState(state)
10281028
.provide({
@@ -1051,8 +1051,8 @@ describe('evalCode', () => {
10511051
codeFilePath,
10521052
context,
10531053
execTime,
1054-
workspaceLocation,
1055-
actionType
1054+
actionType,
1055+
workspaceLocation
10561056
)
10571057
.withState(state)
10581058
.provide({
@@ -1080,8 +1080,8 @@ describe('evalCode', () => {
10801080
codeFilePath,
10811081
context,
10821082
execTime,
1083-
workspaceLocation,
1084-
actionType
1083+
actionType,
1084+
workspaceLocation
10851085
)
10861086
.withState(state)
10871087
.provide([

0 commit comments

Comments
 (0)