redux-persist-immutable icon indicating copy to clipboard operation
redux-persist-immutable copied to clipboard

some state variable not reset properly when reused

Open oliverbienert opened this issue 8 years ago • 5 comments

Hello,

I might have found a bug. I have the following redux tree:

      {
        id: 'landcover_wood',
        name: 'Landcover Wood',
        active: false,
        visible: true,
        style: {
          fill: 'rgba(237, 239, 245, 1)',
          outline: 'rgba(181, 223, 245, 1)'
        },
        origstyle: {
          fill: 'rgba(237, 239, 245, 1)',
          outline: 'rgba(181, 223, 245, 1)'
        }
      },
      {
        id: 'water',
        name: 'Water',
        active: true,
        visible: true,
        style: {
          fill: 'rgba(154, 172, 216, 1)'
        },
        origstyle: {
          fill: 'rgba(225, 231, 245, 1)'
        }
      },

After persisting, the second node also has 'outline' sub elements, but with a value of zero:

      {
        id: 'water',
        name: 'Water',
        active: true,
        visible: true,
        style: {
          fill: 'rgba(154, 172, 216, 1)',
          outline: null
        },
        origstyle: {
          fill: 'rgba(225, 231, 245, 1)',
          outline: null
        }
      },

Can you help out?

Cheers Oliver

oliverbienert avatar Feb 16 '17 15:02 oliverbienert

@oliverbienert that is odd, is outline: null part of initial state?

rt2zz avatar Feb 20 '17 22:02 rt2zz

No, it's not. Initial state is this:

state = Map({
  hidemap: false,
  layers: List()
}

Then I have an action called INIT_LAYERS that fills the layers list with a list of Map objects. Data comes from a mapbox-gl-js instance wrapped in a react component. Some layers have a fill and an outline property (polygon layer such as landcover_wood in my example) some have just a fill colour (such as water or streets). By the way, I also send this part of the redux tree to a REST API to store it in a database. For this to work I convert with toJS() and back with fromJS(), which works. So I suspect the error somewhere in your code but I might be wrong.

oliverbienert avatar Feb 21 '17 08:02 oliverbienert

we use https://github.com/glenjamin/transit-immutable-js to serialize the immutable objects. Perhaps the error lies in there?

I am not sure off the top of my head. Perhaps others will chime in with similar issues.

rt2zz avatar Feb 22 '17 05:02 rt2zz

When I look at my state with the help of ReduxDevTools, the key in question seems to not exist, however when I debug my code, an immutable has("outline") returns true and in the dev tools I indeed see the key but with a value of undefined. So I'm afraid the error is in my code or I need a better understanding of how immutable works. Or it's the way redux works. So for now, sorry for the noise.

oliverbienert avatar Feb 24 '17 18:02 oliverbienert

All good. That sounds strange, and from the outside I have no idea what is going on. If you find resolution please post back here

rt2zz avatar Apr 02 '17 19:04 rt2zz