简体   繁体   English

Redux Reducer不更新状态对象

[英]Redux reducer not updating state object

I have the following code, and I am trying to update the state but it is not working. 我有以下代码,并且我正在尝试更新状态,但是它不起作用。

import Immutable from 'immutable';
import _un  from 'underscore';
import { List, Map } from 'immutable'; 

const defaultState = Map({
  isFetching:true,
  deparments: List(),
  products:List(),
  breadcrumb:List()
})

I am using set but when I console before return it just prints the original object. 我正在使用set,但是在返回之前进行控制台操作时,它只会打印原始对象。 What am I doing wrong? 我究竟做错了什么?

switch(action.type) {
     case 'GET_GALLERY_DATA':

      //console.log("-- api success handler--");
      //console.log(action);

       var depts = getGalleryParsedData(action.res.data);
       var products = getProducts(action.res.data);
       var breadcrumb = getBreadcrumbs(action.res.data);

      state.set('isFetching', true);
      state.set('deparments', List(depts))
      state.set('products', List(products))
      //state.set('breadcrumb', List(breadcrumb))

     console.log("---state----");
     console.log(state);
      return state;

Immutable.js does not mutate your state, it returns a mutated copy of the original object. Immutable.js不会改变您的状态,它会返回原始对象的变异副本。

state = state.set('isFetching', true);
state = state.set('deparments', List(depts));
state = state.set('products', List(products));

or 要么

state = state
  .set('isFetching', true)
  .set('deparments', List(depts))
  .set('products', List(products));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM