Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I found it's complex to handle this type of data in reducer. #1046

Closed
xywenke opened this issue Nov 17, 2015 · 3 comments
Closed

I found it's complex to handle this type of data in reducer. #1046

xywenke opened this issue Nov 17, 2015 · 3 comments
Labels

Comments

@xywenke
Copy link

xywenke commented Nov 17, 2015

I wrote a Tree component with Redux to handle my state , the structure of the state used like this:

let cate = {
  '1': {
    expand: true,
    children: {
      '1_1': {
        expand: false,
        children: {
          '1_1_1': {
            expand: false
          },
          '1_1_2': {
            expand: false
          }
        }
      }
    }
  }
}

When I want to change cate['1']['children']['1_1']['expand'] equal true in reducer , I found it's very difficult with code like

return {
  ...state,
  //Here I don`t know how to do.
} 

I am a fresher in Redux, could you give me a solution? thank you!

@just-boris
Copy link
Contributor

Try https://github.com/facebook/immutable-js. This library does all this work for you.

let cate = Immutable.fromJS({/*your tree will be here*/});
cate.setIn(["1", "children", "1_1", "expand"], true);

@simplesmiler
Copy link

Another option is https://github.com/baptistemanson/immutable-path.

@gaearon
Copy link
Contributor

gaearon commented Nov 17, 2015

This is a duplicate of #994. Use reducer composition pattern. Reducers can call other reducers to handle parts of their state. Also, shopping-cart example in the repo shows how to do it.

@gaearon gaearon closed this as completed Nov 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants