pH200 / cycle-react

Rx functional interface to Facebook's React
MIT License
370 stars 18 forks source link

Add render scheduler to allow usage of refs. #22

Closed corps closed 8 years ago

corps commented 8 years ago

Unfortunately, despite what the README says, refs do not work in the latest version of cycle-react. I should clarify -- they work on the very first ReactDOM.render call, but any other onNext that invokes a set state will build react elements outside of the render context, thus throwing an error.

First, check the test I modified. If you remove my scheduler from the test (removing the .delay call) the test will fail, thus demonstrating the problem.

The fix is not "perfect", but it was a elegant a solution as I could find. It's "opt in". If you want refs, you will need to attach a delay(0, component.scheduler) before the JSX rendering with the refs. The scheduler will essentially do what the vtree function was doing, by "capturing" the vtree context and allowing it to be invoked within the render call.

Let me know what you think about this approach. I need some working ref code, so I am forced to use my branch until we can agree on a fix for master.

pH200 commented 8 years ago

Merged to the render-scheduler branch