convert editor sagas to typed-redux-saga/macro

This commit is contained in:
David Lechner
2021-01-23 18:35:44 -06:00
parent 7be42b143a
commit cdea878e65
+7 -14
View File
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors // Copyright (c) 2020 The Pybricks Authors
import { Ace } from 'ace-builds';
import FileSaver from 'file-saver'; import FileSaver from 'file-saver';
import { select, takeEvery } from 'redux-saga/effects'; import { select, takeEvery } from 'typed-redux-saga/macro';
import { import {
EditorActionType, EditorActionType,
EditorOpenAction, EditorOpenAction,
@@ -15,9 +14,7 @@ import { RootState } from '../reducers';
const decoder = new TextDecoder(); const decoder = new TextDecoder();
function* open(action: EditorOpenAction): Generator { function* open(action: EditorOpenAction): Generator {
const editor = (yield select( const editor = yield* select((s: RootState) => s.editor.current);
(s: RootState) => s.editor.current,
)) as Ace.EditSession | null;
// istanbul ignore next: it is a bug to dispatch this action with no current editor // istanbul ignore next: it is a bug to dispatch this action with no current editor
if (editor === null) { if (editor === null) {
@@ -30,9 +27,7 @@ function* open(action: EditorOpenAction): Generator {
} }
function* saveAs(_action: EditorSaveAsAction): Generator { function* saveAs(_action: EditorSaveAsAction): Generator {
const editor = (yield select( const editor = yield* select((s: RootState) => s.editor.current);
(s: RootState) => s.editor.current,
)) as Ace.EditSession | null;
// istanbul ignore next: it is a bug to dispatch this action with no current editor // istanbul ignore next: it is a bug to dispatch this action with no current editor
if (editor === null) { if (editor === null) {
@@ -46,9 +41,7 @@ function* saveAs(_action: EditorSaveAsAction): Generator {
} }
function* reloadProgram(_action: EditorReloadProgramAction): Generator { function* reloadProgram(_action: EditorReloadProgramAction): Generator {
const editor = (yield select( const editor = yield* select((s: RootState) => s.editor.current);
(s: RootState) => s.editor.current,
)) as Ace.EditSession | null;
// istanbul ignore next: it is a bug to dispatch this action with no current editor // istanbul ignore next: it is a bug to dispatch this action with no current editor
if (editor === null) { if (editor === null) {
@@ -60,7 +53,7 @@ function* reloadProgram(_action: EditorReloadProgramAction): Generator {
} }
export default function* (): Generator { export default function* (): Generator {
yield takeEvery(EditorActionType.Open, open); yield* takeEvery(EditorActionType.Open, open);
yield takeEvery(EditorActionType.SaveAs, saveAs); yield* takeEvery(EditorActionType.SaveAs, saveAs);
yield takeEvery(EditorActionType.ReloadProgram, reloadProgram); yield* takeEvery(EditorActionType.ReloadProgram, reloadProgram);
} }