4 ms·
Seems like .observe() would fix that polling thing, right? http://www.html5rocks.com/en/tutorials/es7/observe/ http://www.html5rocks.com/en/tutorials/es7/obser
by nulltype 11y ago
Seems like .observe() would fix that polling thing, right?
http://www.html5rocks.com/en/tutorials/es7/observe/ http://www.html5rocks.com/en/tutorials/es7/observe/
Also you could just re-render whenever any event happens, which is probably when your state changes anyway.
- Swizec 11y agoIt would if browsers supported it: http://caniuse.com/#search=observe http://caniuse.com/#search=observe So far exists only on Chrome and Android browsers.
- lopatin 11y agoOne reason for the explicit method may be that React does an internal optimization where it batches state updates together. Two calls to setState can result in just one render. https://groups.google.com/forum/#!msg/reactjs/R61kPjs-yXE/ysmpC0IvA4YJ https://groups.google.com/forum/#!msg/reactjs/R61kPjs-yXE/ys...
- masklinn 11y agoNo reason why this wouldn't be possible with Observe, the first call schedules a re-render and the next one doesn't do anything since there's already a re-render scheduled.
- cgag 11y agoObserve just makes making bad apis easier imo. I don't care if react can detect state changes, I want to detect state changes by searching for setState.
- masklinn 11y agoA possible issue is setState doesn't transition the object's state, it creates an async future/pending state transition (and multiple state transitions can be batched). Object.observe can only operate reactively, the state has already changed and the next dereferencing of state data will see the "next state" instead of the "current state".