cityReducer.ts 741 Bytes
Newer Older
1
import { CHANGE_INPUT, ADD_CITY, cityActionTypes } from "./cityActions";
mayi's avatar
mayi committed
2
export interface CityState {
3
  cityInput: string;
mayi's avatar
mayi committed
4 5 6 7
  cityName: string;
  cityLists: { name: string }[];
}
const defaultState: CityState = {
8
  cityInput: "",
mayi's avatar
mayi committed
9 10 11 12 13 14 15
  cityName: "东京",
  cityLists: [
    {
      name: "东京",
    },
  ],
};
16 17
 //eslint-disable-next-line
export default (state = defaultState, action: cityActionTypes) => {
mayi's avatar
mayi committed
18
  switch (action.type) {
19 20 21 22 23 24 25 26 27
    case CHANGE_INPUT:
      return { ...state, cityInput: action.payload };
    case ADD_CITY:
      // console.log(action.payload,'action.payload')
      return {
        ...state,
        cityLists: [...state.cityLists,action.payload],
        cityInput: "",
      };
mayi's avatar
mayi committed
28 29 30
    default:
      return state;
  }
31
};