JavaScript Immutable push/add (redux/immutable.js) immutable redux push

I have an immutable object as my state in a redux reducer, and am trying to add/updates objects to a list.

Here's my reducer:

import { fromJS } from 'immutable'

const initialState = fromJS({
  editable: true
})

export default (state = initialState, action) => {
  switch(action.type) {

    case 'CONTENT_MODE': {
      return state.set('editable', action.editable ? false : true) 
    }

    case 'UPDATE_CONTENT': {
      return state.set(action.page, action.content)
      // action.page = String
      // action.content = {}
    }

    default: {
      return state
    }

  }
}

I want to add objects to the page key, however if it currently exists update the values. I've tried updateIn and add() the callback, but I'm fairly new to immutable.js and am not sure how to approach it correctly.

The set() method rewrites the 'page' value entirely, whilst I need to push the value and only set if it exists, ending up with:

Example

const initialState = fromJS({
  editable: true,
  home: {
    title: {
      name: 'this is the name',
      value: 'this is the value'
    },
    body: {
      name: 'this is the name',
      value: 'this is the value'
    }
  },
  page1: {
    title: {
      name: 'this is the name',
      value: 'this is the value'
    },
    body: {
      name: 'this is the name',
      value: 'this is the value'
    }
  }  
})
Answer:1

I have a unit test that uses spyOn method from jest. import React from 'react'; import expect from 'jest-matchers'; import PointsAwardingPage from '../PointsAwardingPage'; import PointsAwardingForm ...

I have a unit test that uses spyOn method from jest. import React from 'react'; import expect from 'jest-matchers'; import PointsAwardingPage from '../PointsAwardingPage'; import PointsAwardingForm ...

  1. spy on import function
  2. spyon imported function
  3. spyon imported function jest
  4. spyon imported function jasmine
  5. jest spyon imported function

I'm searched a few examples but I don't found anything that solved my problem. My problem is very simple, I need a one element with two events, one tap and double tap event. I do this but the events ...

I'm searched a few examples but I don't found anything that solved my problem. My problem is very simple, I need a one element with two events, one tap and double tap event. I do this but the events ...

How do check if ticketId already inserted into array? This is the code: state = { myState: [], status: 0, limit: 5 }; selected(ticketId) { if (this.state.status < this.state.limit) { ...

How do check if ticketId already inserted into array? This is the code: state = { myState: [], status: 0, limit: 5 }; selected(ticketId) { if (this.state.status < this.state.limit) { ...

  1. react native array map
  2. react native array length
  3. react native array of components
  4. react native array in state
  5. react native array filter
  6. react native array push
  7. react native array of refs
  8. react native array of styles
  9. react native array of images
  10. react native array contains
  11. react native array map example
  12. react native array index
  13. react native array add item
  14. react native array of objects
  15. react native array remove item
  16. react native array get item
  17. react native array to string
  18. react native array find
  19. react native array sort
  20. react native array key value

I'm using angular ui , I've created a directive that its controller listen to the websockets server and retrieve the data, actually it works fine but when leaving the page that loads the directive the ...

I'm using angular ui , I've created a directive that its controller listen to the websockets server and retrieve the data, actually it works fine but when leaving the page that loads the directive the ...