PromucFlow_constructor/app/client/src/sagas/InitSagas.ts

69 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-11-01 07:11:32 +00:00
import { all, select, put, takeLatest, take } from "redux-saga/effects";
2019-11-08 11:02:00 +00:00
import {
ReduxAction,
ReduxActionTypes,
} from "../constants/ReduxActionConstants";
2019-11-01 07:11:32 +00:00
import {
getPropertyPaneConfigsId,
getCurrentPageId,
} from "../selectors/editorSelectors";
import { fetchEditorConfigs } from "../actions/configsActions";
import { fetchPage, fetchPageList } from "../actions/pageActions";
import { fetchActions } from "../actions/actionActions";
2019-11-07 09:32:38 +00:00
import { fetchDatasources } from "../actions/datasourcesActions";
2019-11-13 07:34:59 +00:00
import { initBindingMapListener } from "../actions/bindingActions";
2019-11-01 07:11:32 +00:00
2019-11-08 11:02:00 +00:00
function* initializeEditorSaga() {
2019-11-01 07:11:32 +00:00
// Step 1: Start getting all the data needed by the app
const propertyPaneConfigsId = yield select(getPropertyPaneConfigsId);
const currentPageId = yield select(getCurrentPageId);
yield all([
2019-11-13 07:34:59 +00:00
put(initBindingMapListener()),
2019-11-01 07:11:32 +00:00
put(fetchPageList()),
2019-11-08 11:02:00 +00:00
put(fetchEditorConfigs({ propertyPaneConfigsId })),
2019-11-01 07:11:32 +00:00
put(fetchPage(currentPageId)),
put(fetchActions()),
2019-11-07 09:32:38 +00:00
put(fetchDatasources()),
2019-11-01 07:11:32 +00:00
]);
// Step 2: Wait for all data to be in the state
yield all([
take(ReduxActionTypes.FETCH_PAGE_LIST_SUCCESS),
take(ReduxActionTypes.UPDATE_CANVAS),
take(ReduxActionTypes.FETCH_ACTIONS_SUCCESS),
2019-11-07 09:32:38 +00:00
take(ReduxActionTypes.FETCH_DATASOURCES_SUCCESS),
2019-11-01 07:11:32 +00:00
]);
2019-11-13 07:34:59 +00:00
// Step 3: Create the success;
yield put({
type: ReduxActionTypes.INITIALIZE_EDITOR_SUCCESS,
2019-11-13 07:34:59 +00:00
});
2019-11-01 07:11:32 +00:00
}
2019-11-08 11:02:00 +00:00
export function* initializeAppViewerSaga(
action: ReduxAction<{ pageId: string }>,
) {
2019-11-13 07:34:59 +00:00
yield put(initBindingMapListener());
2019-11-08 11:02:00 +00:00
yield all([put(fetchPageList()), put(fetchActions())]);
yield all([
take(ReduxActionTypes.FETCH_PAGE_LIST_SUCCESS),
take(ReduxActionTypes.FETCH_ACTIONS_SUCCESS),
]);
yield put({
type: ReduxActionTypes.FETCH_PUBLISHED_PAGE_INIT,
payload: action.payload,
});
2019-11-14 12:16:11 +00:00
yield take(ReduxActionTypes.UPDATE_CANVAS);
2019-11-13 07:34:59 +00:00
yield put({
type: ReduxActionTypes.INITIALIZE_EDITOR_SUCCESS,
2019-11-13 07:34:59 +00:00
});
2019-11-08 11:02:00 +00:00
}
2019-11-01 07:11:32 +00:00
export default function* watchInitSagas() {
2019-11-08 11:02:00 +00:00
yield all([
takeLatest(ReduxActionTypes.INITIALIZE_EDITOR, initializeEditorSaga),
2019-11-08 11:02:00 +00:00
takeLatest(
ReduxActionTypes.INITIALIZE_PAGE_VIEWER,
initializeAppViewerSaga,
),
]);
2019-11-01 07:11:32 +00:00
}