thomasboyt / react

React is a JavaScript library for building user interfaces. It's declarative, efficient, and extremely flexible. What's more, it works with the libraries and frameworks that you already know.
http://facebook.github.io/react/
Other
0 stars 1 forks source link

Update _nodeIndex when child changes #7

Open thomasboyt opened 9 years ago

thomasboyt commented 9 years ago

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 commented 9 years ago

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

thomasboyt commented 9 years ago

this is, if nothing else, a predicted problem: https://github.com/facebook/react/issues/2127#issuecomment-108067345

[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 commented 9 years ago

options:

thomasboyt commented 9 years ago

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.