mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
convert license sagas to typed-redux-saga/macro
This commit is contained in:
+7
-10
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user