SHOW:
|
|
- or go back to the newest paste.
| 1 | export function formReducer(state: IFormState = getDefaultFormState(), action: Action): IFormState { | |
| 2 | switch(action.type) { | |
| 3 | ... | |
| 4 | case COUNTRIES_LOADED: { | |
| 5 | const typedAction = <ICountriesLoadedAction>action; | |
| 6 | return { ...state, countries: typedAction.payload.countries }; | |
| 7 | } | |
| 8 | case FORM_COUNTRY_CHANGED: { | |
| 9 | const typedAction = <IFormCountryChangedAction>action; | |
| 10 | return { ...state, country: typedAction.payload.country, isDirty: true }; | |
| 11 | } | |
| 12 | case CITIES_FOR_COUNTRY_LOADED: { | |
| 13 | const typedAction = <ICitiesForCountryLoadedAction>action; | |
| 14 | return { ...state, cities: typedAction.payload.cities }; | |
| 15 | } | |
| 16 | case FORM_CITY_CHANGED: { | |
| 17 | const typedAction = <IFormCityChangedAction>action; | |
| 18 | return { ...state, city: typedAction.payload.city, isDirty: true }; | |
| 19 | } | |
| 20 | default: { | |
| 21 | return state; | |
| 22 | } | |
| 23 | } | |
| 24 | } |