Plummer
Plummer

Reputation: 6688

seamless-immutable is not updating state consistently

I'm working with seamless-immutable and redux, and I'm getting a strange error when updating the state. Here's my code, without the bits like the action return or combineReducers. Just the junk that's running/causing the error.

Initial State

{ 
  things: {
    fetching: false,
    rows: []
  }
}

Action Handler

export default {
  [DEALERS_REQUEST]: (state, action) => {
    return Immutable({ ...state, fetching: true });
  },
  [DEALERS_RECEIVE]: (state, action) => {
    return Immutable({ ...state, rows: action.payload, fetching: false });
},

Middleware with thunk

export const thingsFetch = (data) => {
  return (dispatch, getState) => {
    dispatch(thingsRequest());
    dispatch(thingsReceive(data));
  }
}

Now, what's weird is, if I run these two actions together, everything is fine.

If I only dispatch thingsRequest(), I get a "cannot push to immutable object" error.

I've tried using methods like set, update, replace, merge, but they usually return with "this.merge is not a function".

Am I doing something wrong procedurally or should I contact the module dev to report an issue?

Upvotes: 0

Views: 413

Answers (1)

Plummer
Plummer

Reputation: 6688

This issue on this was that, on the case of an empty array, the component was trying to write back to the Immutable object with it's own error message.

To get around this, I pass the prop as mutable. There's also some redux-immutable modules that replace the traditional connect function to all the app to pass mutable props to components while maintaining immutability in the state.

Upvotes: 0

Related Questions