My current state object structure (with nested arrays) is as follows:
state = { pages: [ { notes: [ { … }, … ] }, … ] }
So, to edit a note, I have to go through the pages to find the right page (i.e. pages.findIndex(page => page.id === pageIdArgument)), go through the notes to find the right note, and then edit the note.
I’m thinking of switching to a structure (with nested objects) like the following:
state = { pages: { pageId: { notes: { noteId: { … }, … } }, … } }
To edit a note with the nested object structure, I would be able to find the right page by id (without needing to iterate through a pages array) and find the right note to edit by id (without needing to iterate through a notes array).
So, my original question of whether to use nested arrays or nested objects can be broken down into the following questions:
Is my reasoning correct that it would be more performant to have nested objects instead of nested arrays? Assuming that one note get edited frequently (e.g. multiple edits per second) and that there are a lot of notes (e.g. >10,000 notes), would there be a noticeable performance difference between having nested arrays and having nested objects (or does it not matter which one I use)?
submitted by /u/CaterpillarSea3908
[link] [comments]