import { ofType } from 'redux-observable';
import { of } from 'rxjs';
import { switchMap } from 'rxjs/operators';

import { loadingAction } from '../slices';
import { errorEventAction, requestEventAction, responseEventAction } from '@/modules/@common/request/redux/slices';

export default (action$) =>
  action$.pipe(
    ofType(requestEventAction.type, responseEventAction.type, errorEventAction.type),
    switchMap((action) => of(loadingAction(action.type === requestEventAction.type))),
  );
