immutableJs Update object key with second order of Map

1

Good afternoon, I'm in a project where I have to use Redux for the status of my application in Meteor , but when handling a reduced type object I had to use > ImmutableJs where when using the .set property to change the value of a key of this type:

const stateMenu = {
  menu0: {
    nombre: 'Adm de PBX',
    activo: false,
    abierto: false,
    habilitado: true,
    iconItem: "fa fa-server"
  },
 menu1: {
    nombre: 'Video Conferencia',
    activo: false,
    abierto: false,
    habilitado: true,
    iconItem: "fa fa-video-camera"
  },
}

The reducer has this style

export function menu(state = map(stateMenu), action) {
      switch (action.type) {
        ...
      }
    }

The return of a switch case

return state.set('menu0.abierto', true); 

it does not work for me like that

return state.menu0.set('abierto', true);

could you help me see how to change the value of the second level objects of the stateMenu with immutablejs

Thanks.!

    
asked by Luis Cauro 04.01.2017 в 17:12
source

1 answer

1

The function that can serve you is setIn . The first parameter must be an array with depth levels, the second parameter, the new value.

state.setIn(['menu0', 'abierto'], true);
    
answered by 04.01.2017 / 22:37
source