winjs / react-winjs

React wrapper around WinJS's controls
MIT License
206 stars 47 forks source link

[Question] How do you manage virtualization ? #18

Closed darkyen closed 9 years ago

darkyen commented 9 years ago

In scenarios like ListView when virtualization is enabled, there will be two different virtualization techniques at work, winjs trying to re-use the element and react too, how is this case handled ?

rigdern commented 9 years ago

React does not manage the ListView's DOM. Only the ListView manages it. ListView communicates this to React by returning false in shouldComponentUpdate.

Does that answer your question?

darkyen commented 9 years ago

Who renders the element itself ? If I understand it correctly the template designed in react can only be rendered via react ?

rigdern commented 9 years ago

ListView decides when each item is created and rendered. ListView creates an element per item. It's up to the renderer/template to fill in that element with content.

In the case of ReactWinJS, the renderer is expressed as a function which returns a React component (due to ReactWinJS.reactRenderer). When the renderer function is called, it calls React.render to mount a React component inside of the element for the item.

When you scroll a sufficient distance away from the item, ListView will unrealize it to save memory. When it does this, it calls dispose on the item's element. ReactWinJS.reactRenderer implements dispose such that it will unmount the corresponding React component.

darkyen commented 9 years ago

Ah makes sense, there is slight overhead too but makes sense.