4 ms·
The problem is that generators are not that widely supported (yet). You could replace CSP with something like Bacon.js and likely achieve the same effect (don't
by tzaman 11y ago
The problem is that generators are not that widely supported (yet). You could replace CSP with something like Bacon.js and likely achieve the same effect (don't have an example, but I'm researching the area for a new project)
- xtrumanx 11y agoAren't generators part of Babel? As long as you target ES5 shouldn't you be able to use generators via Babel?
- kenOfYugen 11y agoGenerator functions are part of ES6/2015 and are supported by babel. But keep note that downgrading them to ES5 spec. includes a performance trade-off.
- jevakallio 11y agoTake a look at http://cycle.js.org http://cycle.js.org - it implements essentially the same concept using RxJS instead of csp and virtual-dom instead of React.
- stardrive 11y agoExcept remember, RxJS is also a growing standard and the virtual-DOM Cycle.js uses has been tested to be a fair amount faster and robust than the one React has. Then there is also Cycle's Model-View-Intent pattern and leading edge work on component integration, which is in line with W3C standards. Cycle's drivers also allow Cycle.js to integrate or target many options. Things have been fragmented and Cycle.js seems to have brought the best together, representing a new and intelligent vortex of progress. Before I took the time to understand what Cycle.js was about I was naive and thought React was it. I now understand how poorly it's reactivity has been implemented. On the other hand Cycle.js is fully reactive and has brought structure, flow and a sense of intelligence back to my app development.
- jarpineh 11y agoFor a light weight, ES5 style version, I have used a function generator (or factory, if you prefer). It keeps iteration state in its closure, and the resulting function updates it when its called. Your code calls generated function from then on. You can easily use arguments to reset the state, or to get something else to happen. function gen_f() { var count = 0; function f() { count += 1; return count; } return f; } Probably you could use csp.take(channel) like in OP this way, too. I used this solution primarily because I couldn't figure out how generators handle arguments in iteration calls. My problem was to find a string that should be returned for a given index (where there was some complex rules on what string was active when) and to keep looping a list indefinitely. Generators seem to make things syntactically cleaner, but for me at least reasoning about them has been challenging in JS context.
- kenOfYugen 11y agoThey are widely supported: https://facebook.github.io/regenerator/ https://facebook.github.io/regenerator/ Yes, you can replace CSP with Rx style libraries. It's just a different kind of learning curve. Personally I prefer CSP, as channels are a more primitive approach to writing concurrent applications. CSP is like a library and Bacon/Rx are like frameworks.