PromucFlow_constructor/app/client/src/sagas/BatchSagas.tsx
Abhinav Jha 543b7ec72d
Entity Explorer Render (#1354)
* WIP: Performance improvements in entity explorer

* WIP: Achieve feature parity for entity explorer with release

* Update unit tests

* Add sentry profiling to current page entity properties component

* Fix page add/delete not showing up on entity explorer issue. Update memoization logic for pagegroup entity

* Deal with the ban-ts-ignore eslint issues

* Update unit tests

* Fix widget entity children visibility

* Fix tests and code

* Fix tests for scenarios where the collapsed entities are unmount, as this is a part of the performance optimization

* Filter undefined children when generating structureDSL

* Remove rule from eslintrc

Consolidate createPage test command

* Update CreatePage tests to remove redundant dsl updates

* Revert CreatePage test changes, as adding more checks within this command globally causes other tests to have issues.

* re-enable eslint rule, as without it CI tests fail

* Revert to ban-ts-comment

* Fix typescript ban-ts-ignore issue by upgrading react-scripts and fixing typescript issue across the application

* Typescript errors handled

Co-authored-by: vicky-primathon.in <vicky.bansal@primathon.in>
2020-11-03 18:35:40 +05:30

77 lines
2.2 KiB
TypeScript

/* eslint-disable @typescript-eslint/ban-ts-comment */
import _ from "lodash";
import { put, debounce, takeEvery, all } from "redux-saga/effects";
import { ReduxAction, ReduxActionTypes } from "constants/ReduxActionConstants";
import { batchActionSuccess } from "../actions/batchActions";
const BATCH_PRIORITY = {
[ReduxActionTypes.SET_META_PROP]: {
priority: 0,
needsSaga: false,
},
[ReduxActionTypes.RESET_WIDGET_META]: {
priority: 0,
needsSaga: false,
},
[ReduxActionTypes.UPDATE_WIDGET_PROPERTY]: {
priority: 0,
needsSaga: false,
},
[ReduxActionTypes.EXECUTE_ACTION]: {
priority: 1,
needsSaga: true,
},
[ReduxActionTypes.EXECUTE_PAGE_LOAD_ACTIONS]: {
priority: 1,
needsSaga: true,
},
[ReduxActionTypes.UPDATE_ACTION_PROPERTY]: {
priority: 0,
needsSaga: false,
},
[ReduxActionTypes.UPDATE_ACTION_INIT]: {
priority: 1,
needsSaga: true,
},
};
const batches: ReduxAction<any>[][] = [];
function* storeUpdatesSaga(action: ReduxAction<ReduxAction<any>>) {
try {
const priority = BATCH_PRIORITY[action.payload.type].priority;
const currentPriorityBatch = batches[priority] || [];
currentPriorityBatch.push(action.payload);
_.set(batches, `[${priority}]`, currentPriorityBatch);
yield put({ type: ReduxActionTypes.EXECUTE_BATCH });
} catch (e) {
console.error(`${action.payload.type} action priority not set`);
}
}
function* executeBatchSaga() {
for (let priority = 0; priority < batches.length; priority++) {
const batch = batches[priority];
if (Array.isArray(batch) && batch.length) {
const needsSaga = batch.filter(b => BATCH_PRIORITY[b.type].needsSaga);
const canBatch = batch.filter(b => !BATCH_PRIORITY[b.type].needsSaga);
batches[priority] = [];
// @ts-ignore: No types available
yield put(canBatch);
if (needsSaga.length) {
for (const sagaAction of needsSaga) {
yield put(sagaAction);
}
}
yield put(batchActionSuccess(batch));
}
}
}
export default function* root() {
yield all([
debounce(20, ReduxActionTypes.EXECUTE_BATCH, executeBatchSaga),
takeEvery(ReduxActionTypes.BATCHED_UPDATE, storeUpdatesSaga),
]);
}