Skip to content

Commit 0854c6e

Browse files
committed
Refactor eval code to utilize more type safety
1 parent 0bc8556 commit 0854c6e

File tree

2 files changed

+226
-214
lines changed

2 files changed

+226
-214
lines changed

src/commons/sagas/SafeEffects.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import { ActionMatchingPattern } from '@redux-saga/types';
1+
import type { ActionMatchingPattern } from '@redux-saga/types';
22
import * as Sentry from '@sentry/browser';
33
import {
4-
ActionPattern,
5-
ForkEffect,
6-
HelperWorkerParameters,
4+
type ActionPattern,
5+
type ForkEffect,
6+
type HelperWorkerParameters,
7+
select,
78
takeEvery,
89
takeLatest,
910
takeLeading
1011
} from 'redux-saga/effects';
12+
import type { StoriesEnvState } from 'src/features/stories/StoriesTypes';
13+
14+
import type { OverallState } from '../application/ApplicationTypes';
15+
import type { WorkspaceLocation, WorkspaceManagerState } from '../workspace/WorkspaceTypes';
1116

1217
// it's not possible to abstract the two functions into HOF over takeEvery and takeLatest
1318
// without stepping out of TypeScript's type system because the type system does not support
@@ -95,3 +100,13 @@ export function safeTakeLeading<P extends ActionPattern, Fn extends (...args: an
95100
}
96101
return takeLeading<P, typeof wrappedWorker>(pattern, wrappedWorker, ...args);
97102
}
103+
104+
export function* selectWorkspace<T extends WorkspaceLocation>(workspaceLocation: T) {
105+
const workspace: WorkspaceManagerState[T] = yield select((state: OverallState) => state.workspaces[workspaceLocation])
106+
return workspace
107+
}
108+
109+
export function* selectStoryEnv(storyEnv: string) {
110+
const workspace: StoriesEnvState = yield select((state: OverallState) => state.stories.envs[storyEnv])
111+
return workspace
112+
}

0 commit comments

Comments
 (0)