Был предложен рефакторинг этого. Код работает, но не уверен, что он в итоге сломается:
export function* fetchWidgetDataIfRequired(action) {
yield call(taggedDelay, 102);
const { dashboardId, dashboardType } = action.payload;
const dashboard = yield select(makeSelectDashboard({ dashboardId, dashboardType }));
const widgetData = yield select(makeSelectWidgets());
const dashboardWidgets = dashboard.getIn(['config', 'widgets']);
// get all widgets that have userWidgetId but no widgetLayoutData
// NOTE: if you do not do valueSeq(), it will still work but it will throw a warning about
// > [...effects] has been deprecated in favor of all([...effects]), please update your code
const fetchWidgetLayoutDataActions = dashboardWidgets.filter((widget) => {
'';
const userWidgetId = widget.get('userWidgetId');
return userWidgetId != null
&& widgetData.getIn([userWidgetId, 'widgetLayoutData']) == null;
}).map((widget) => yield spawn(fetchWidgetLayoutData, { dashboardType, dashboardId, widget })).valueSeq().toArray();
// console.error('fetchdata', {
// fetchWidgetLayoutDataActions,
// });
yield all(fetchWidgetLayoutDataActions);
// get all widgets that have userWidgetId but no widgetData
const fetchWidgetDataActions = dashboardWidgets.filter((widget) => {
const userWidgetId = widget.get('userWidgetId');
return userWidgetId != null
&& widgetData.getIn([userWidgetId, 'widgetData']) == null;
}).map((widget) => {
const userWidgetId = widget.get('userWidgetId');
const delay = widget.get('y', 0) * 250 + 6;
// const delay = 100;
return spawn(fetchWidgetData, { userWidgetId, delay });
}).valueSeq().toArray();
yield all(fetchWidgetDataActions);
}
Я получаю эту ошибку:
A 'yield' expression is only allowed in a generator body.ts(1163)
Я хотел бы посмотрите, как это можно лучше кодировать, чтобы избежать этой ошибки.