import { SampleApi } from '../../api' ; import { WeatherActionType } from './types' ; import type { ReduxAction , AppThunk } from '../' ; import type { WeatherForecastPayload } from './types' ; export const actionCreators = { resetState : ( ) : ReduxAction < WeatherForecastPayload > => ( { type : WeatherActionType . RESET_STATE , } ) , requestWeatherForecasts : ( startDateIndex ) : AppThunk < WeatherForecastPayload > => async ( dispatch , getState ) => { if ( startDateIndex === getState ( ) . weatherForecasts . startDateIndex ) { return ; } dispatch ( { payload : { startDateIndex } , type : WeatherActionType . REQUEST , } ) ; try { const forecasts = await SampleApi . getWeatherForecastsAsync ( startDateIndex ) ; dispatch ( { type : WeatherActionType . RECEIVE , payload : { forecasts , startDateIndex } , } ) ; } catch ( e ) { console . error ( e ) ; } } , } ;