News for hackers. Stuff that matters.
Re:A simpler web architecture using React, Flux, CSP, and FR... by tzaman on Saturday August 15, 2015 @04:44AM (#10064754)
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)
Re:A simpler web architecture using React, Flux, CSP, and FR... by jarpineh on Saturday August 15, 2015 @05:20AM (#10064821)
For 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.
Re:A simpler web architecture using React, Flux, CSP, and FR... by jevakallio on Saturday August 15, 2015 @04:55AM (#10064770)
Take a look at http://cycle.js.org - it implements essentially the same concept using RxJS instead of csp and virtual-dom instead of React.
Re:A simpler web architecture using React, Flux, CSP, and FR... by stardrive on Saturday August 15, 2015 @03:36PM (#10066535)
Except 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.

Re:A simpler web architecture using React, Flux, CSP, and FR... by kenOfYugen on Saturday August 15, 2015 @05:44AM (#10064870)
They are widely supported: 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.

Re:A simpler web architecture using React, Flux, CSP, and FR... by xtrumanx on Saturday August 15, 2015 @04:51AM (#10064763)
Aren't generators part of Babel? As long as you target ES5 shouldn't you be able to use generators via Babel?
Re:A simpler web architecture using React, Flux, CSP, and FR... by kenOfYugen on Saturday August 15, 2015 @05:50AM (#10064887)
Generator 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.