0

imagine I have this state

const state = [
{text: 'node1'},
{text: 'node2', children: [
    {text: 'subNode1'},
    {text: 'subNode2', children: [
        {text: 'node1'}]
    }]
}]

So as a requirement, this tree structure can go nested arbitrarily. I want to be able to address the array item {text: 'node1'}; the nested one inside node2->subNode2 such that I can edit it and also find that it is a duplicate (has same text) to the one with index 0 in the state array.

Can you help me with that? I need to have a reducer that can mutate the state to reflect this issue given that the nesting can go arbitrarily deeper.

Many Thanks! Muchtar

Muchtar
  • 3
  • 2
  • please provide more details as to what you're trying to achieve exactly, with code or pseudocode examples in how you imagine the relations between parent-child work, etc. otherwise, nobody can help you because it's not clear enough. (images / drawings explaining your intent is also great.) – Denialos Aug 13 '17 at 16:53
  • @Denialos Thanks! Now I edited it. I hope it is clearer. – Muchtar Aug 13 '17 at 18:06
  • I found this post that elaborates on my problem. https://stackoverflow.com/questions/25569255/find-and-modify-deeply-nested-object-in-javascript-array – Muchtar Aug 13 '17 at 22:55

1 Answers1

0

Redux with ImmutableJs and recursion can solve my problem. My state nodes must have unique IDs regardless of their depths. Credits go to this nice post

Immutable.js structure (updating nested map)?

I hope this can help others.

Muchtar
  • 3
  • 2