import { TimelineItem } from 'src/models/requests/timeline' ; import createReducer from 'src/store/utils/createReducer' ; import { OBSERVE_TIMELINE , TimelineState } from './types' ; const initialState = { loading : false , observerReceivedFirstUpdate : false , data : undefined , error : undefined , } ; export default createReducer < TimelineState > ( { [ OBSERVE_TIMELINE . SUBSCRIBE ] : ( state ) => { state . loading = true ; } , [ OBSERVE_TIMELINE . UPDATED ] : ( state , { payload , } ) => { state . data = payload . docs . map ( doc => doc . data ( ) ) ; state . loading = false ; state . observerReceivedFirstUpdate = true ; } , [ OBSERVE_TIMELINE . ERROR ] : ( state , { payload } ) => { state . error = payload ; state . loading = false ; } , } , initialState ) ;