convert license sagas to typed-redux-saga/macro

This commit is contained in:
David Lechner
2021-01-23 18:26:57 -06:00
parent 97a2a6671b
commit 19d8f9ce3a
+7 -10
View File
@@ -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);
}