- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
import { combineEpics, ofType } from 'redux-observable'
import { map, switchMap, catchError, filter, mergeAll } from 'rxjs/operators'
import { of, from } from 'rxjs'
import * as R from 'ramda'
import * as TICKETS_ACTION_TYPES from './tickets.types'
import * as TicketsActions from './tickets.actions'
import * as TicketsSelectors from './tickets.selectors'
import { /* TICKET_TYPES,*/ TICKET_STEPS } from './constants'
import mockAPI from 'services/mockAPI'
export const getTicketsEpic = (action$, state$) =>
from(
R.map(
(step) =>
action$.pipe(
filter(
R.either(
R.both(R.propEq('type', TICKETS_ACTION_TYPES.GET_TICKETS_BY_STEP), R.pathEq(['payload', 'step'], step)),
R.propEq('type', TICKETS_ACTION_TYPES.GET_ALL_TICKETS)
)
),
switchMap((action) => {
if (
action.type !== TICKETS_ACTION_TYPES.GET_ALL_TICKETS &&
TicketsSelectors.ticketsAllDirtySelector(state$.value)
) {
return of(TicketsActions.getAllTickets())
} else if (!TicketsSelectors.ticketsByStepDirtySelector(step, state$.value)) {
return of(TicketsActions.getTicketsByStepSuccess(step, null, true))
}
return from(
// Mocks tickets API
// TODO: Replace by real request
mockAPI.getTicketsByStep(step)
).pipe(
map((data) => TicketsActions.getTicketsByStepSuccess(step, data)),
catchError((err) => of(TicketsActions.getTicketsByStepError(step, err)))
)
})
),
R.values(TICKET_STEPS)
)
).pipe(mergeAll())
Редукс нам уже не интересен, нам с поподвыподвертами подавай, чтоб тупо болванку показать.