From 19d8f9ce3add8b06f0d18e9012c88bbc1789c0bc Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 23 Jan 2021 18:26:57 -0600 Subject: [PATCH] convert license sagas to typed-redux-saga/macro --- src/sagas/license.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/sagas/license.ts b/src/sagas/license.ts index 0bd1eac0..cb672624 100644 --- a/src/sagas/license.ts +++ b/src/sagas/license.ts @@ -1,32 +1,29 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2021 The Pybricks Authors -import { call, put, select, takeEvery } from 'redux-saga/effects'; +import { call, put, select, takeEvery } from 'typed-redux-saga/macro'; import { AppActionType } from '../actions/app'; import { didFailToFetchList, didFetchList } from '../actions/license'; import { RootState } from '../reducers'; -import { LicenseList } from '../reducers/license'; function* fetchLicenses(): Generator { - const licenses = (yield select( - (s: RootState) => s.license.list, - )) as LicenseList | null; + const licenses = yield* select((s: RootState) => s.license.list); // if we already have license list, nothing to do if (licenses !== null) { return; } - const response = (yield call(() => fetch('static/oss-licenses.json'))) as Response; + const response = yield* call(() => fetch('static/oss-licenses.json')); if (!response.ok || response.body === null) { - yield put(didFailToFetchList(response)); + yield* put(didFailToFetchList(response)); return; } - const list = (yield call(() => response.json())) as LicenseList; - yield put(didFetchList(list)); + const list = yield* call(() => response.json()); + yield* put(didFetchList(list)); } export default function* (): Generator { - yield takeEvery(AppActionType.OpenLicenseDialog, fetchLicenses); + yield* takeEvery(AppActionType.OpenLicenseDialog, fetchLicenses); }