vanyahuk
@vanyahuk

Почему при обновлении 1-го редюсера онуляеться второй?

при обновлении одного редюсера почему-то сбрасываються свойства второго

import { combineReducers } from 'redux';
import filterParams from './filterParams';

import filterAjaxParams from './filterAjaxParams';

import api from './api';

export default combineReducers({

filterParams: filterParams,

filterAjaxParams: filterAjaxParams,

})


при обновлении filterAjaxParams сбрасываються свойства filterParams

const filterAjaxParams = (state = [], action) => {



switch (action.type) {

    case "UPDATE_AJAX_PARAMS" :

        return Object.assign({}, state, action.payload);

    default: return{

            types: [],


            brands: [],


            models: [],


            years: [],


            regions: [],


        }
}
}

export default filterAjaxParams;


const filterParams = (state = [], action) => {


	switch( action.type ){

		case "UPDATE_CHANGED":
			return Object.assign({}, state, action.payload );


		case "UPDATE_ADVENTURE_STATE":

			return Object.assign({}, state, action.payload );



		default : return {

			filter_models: {

				adventure_state: null,

				type_id: null,

				bodies: [],

				brands: [],

				models: [],

				countries: [],

				ignore_countries: null,

				ignore_brands: null,

				ignore_models: null


			},

			additionally_filter: {

				years: {

					from: null,

					to: null,
				},

				price: {

					from: null,

					to:   null
				},

				auction_possible: null,

				exchange_car: null,

				inexpensive: null,

				broken: null,

				after_an_accident: null,

				currency_id: null

			},

			region: {

				regions: [],

				cities: [],

				search_neighborns: null
			},

			specifications:  {

				fuels: [],

				transmissions: [],

				count_doors: {

					from: null,

					to: null

				},

				seats_number: {

					from: null,

					to: null

				},

				volume: {

					from: null,

					to: null

				},

				power: {

					from: null,

					to: null

				},

				race: {

					from: null,

					to: null
				},

				colors: {

					items: [],

					metallic: null
				},


				options: []

			},


			page: null,

			sort: null,

			period: null

		};
	}

}

export default filterParams;

5ace30170c003907844761.png

я обновляю filterAjaxParams.years
5ace3169c05a6909504448.png
но при етом сбрасываються свойства filterParams
5ace3189d126f835345089.png
  • Вопрос задан
  • 94 просмотра
Пригласить эксперта
Ответы на вопрос 1
monochromer
@monochromer
DIVeloper
В редьюсере нужно по умолчанию возвращать уже имеющeеся состояние
function reducer(state = initialState, action) {
  switch (action.type) {
     // ...
    default:
      return state
  }
}

Форматируйте код перед публикацией вопроса
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы