mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-15 01:01:43 +10:00
37 lines
992 B
TypeScript
37 lines
992 B
TypeScript
import { Resume } from '@reactive-resume/schema';
|
|
import debounce from 'lodash/debounce';
|
|
import { select, takeLatest } from 'redux-saga/effects';
|
|
|
|
import { updateResume } from '@/services/resume';
|
|
import { AppDispatch, RootState } from '@/store/index';
|
|
|
|
import {
|
|
addItem,
|
|
addSection,
|
|
deleteItem,
|
|
deleteSection,
|
|
duplicateItem,
|
|
editItem,
|
|
setResume,
|
|
setResumeState,
|
|
} from '../resume/resumeSlice';
|
|
|
|
const DEBOUNCE_WAIT = 1000;
|
|
|
|
const debouncedSync = debounce((resume: Resume, dispatch: AppDispatch) => updateResume(resume).then((resume) => dispatch(setResume(resume))), DEBOUNCE_WAIT);
|
|
|
|
function* handleSync(dispatch: AppDispatch) {
|
|
const resume: Resume = yield select((state: RootState) => state.resume.present);
|
|
|
|
debouncedSync(resume, dispatch);
|
|
}
|
|
|
|
function* syncSaga(dispatch: AppDispatch) {
|
|
yield takeLatest(
|
|
[setResumeState, addItem, editItem, duplicateItem, deleteItem, addSection, deleteSection],
|
|
() => handleSync(dispatch)
|
|
);
|
|
}
|
|
|
|
export default syncSaga;
|