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

Update _nodeIndex when child changes #7

Open
thomasboyt opened this issue Jun 3, 2015 · 4 comments
Open

Update _nodeIndex when child changes #7

thomasboyt opened this issue Jun 3, 2015 · 4 comments

Comments

@thomasboyt
Copy link
Owner

This is pretty difficult & important.

When the following structure changes from:

<Main>
  <Composite : frag>
    <one />
    <two />
  </Composite>
  <Composite : frag>
    <one />
    <two />
  </Composite>
</Main>

to:

<Main>
  <Composite : frag>
    <one />
  </Composite>
  <Composite : frag>
    <one />
    <two />
  </Composite>
</Main>

the only update cycle that gets called is for the first composite, and the second one doesn't know that a previous sibling fragment was updated, so its _nodeIndex is now off by one.

@thomasboyt
Copy link
Owner Author

wonder if there's a way to trigger some index-updating cycle on Main, given that a child fragment changed...

@thomasboyt
Copy link
Owner Author

this is, if nothing else, a predicted problem: facebook#2127 (comment)

[referencing nodes by mountIndex] does not work when one "node" can suddenly become any number of nodes and this may happen without invoking the parent and it may also happen several components deep (wrapping)

@thomasboyt
Copy link
Owner Author

options:

  • when a composite component's update cycle is hit, if its nodeCount changes, trigger some way to increase the nodeIndexes of subsequent siblings
    • concerned that there's not going to be a simple, and almost certainly not an efficient, way to look up siblings
  • trigger the parent update cycle when a fragment changes
    • horrible performance indications, adds user-facing special-case behavior to fragments that we should be trying to avoid, this is a garbage option
  • call some method on the parent that only updates nodeIndexes
    • basically equivalent to the first option
    • parent.updateNodeIndexes(thisIndex, newNodeCount)
    • how do we look up the parent in a performant way?
    • can the parent access the children after some nodeIndex in a performant manner? sounds like an expensive filter

@thomasboyt
Copy link
Owner Author

The frustrating thing about accessing the parent is that there doesn't seem to be a good way to do it, at all.

I'm imagining a CompositeComponent storing a reference to its parent, somehow, but I don't know if the parent could change out from under it after initial mount. Looking up by root ID seems to be (a) impossible and (b) a super-gross hack even if it was.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant