by Swizec · 11y ago · 0 comments
Without explicit functions to be called, you can't detect state changes and would need polling. This is terrible.
At the end of the day, it's a limitation of JavaScript because unlike with Python, for example, you can't have automagic getter/setter functions. They have to be called as functions.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guid...
AmpersandJS, for example, implements its observable pattern in this way:
http://ampersandjs.com/learn/state
That said, I don't think the pubsub/rx/observables pattern is the most optimal for UI development, since it still allows for cascading event chains. Modeling all application state as a large data structure that allows for efficient diffing — which nicely mirrors the diffing react does with both it's internal component tree and diffing with the DOM — is a much more straightforward approach. Just re-render your application 60 times a second, like a game engine, and make that process as efficient as possible.
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.
So far exists only on Chrome and Android browsers.
https://groups.google.com/forum/#!msg/reactjs/R61kPjs-yXE/ys...