Kickstarter Survey

In notebook:
FrontEndMasters Real-Time Web with Node.js
Created at:
2015-10-13
Updated:
2015-10-14
Tags:
JavaScript
Video Course on Real-Time HTML5 with Node.jsA survey site he did for Kickstarter.

A good example of middle-end architecture

You-Dont-Know-JS/kickstarter-survey-site at master · getify/You-Dont-Know-JS
  function doGetProfile(req,res) {
	collectPostData(req)
	.val(processJSONPostData)
	.val(function(sessionData){
		return sessionData.session_id;
	})
	.seq(validateSession)
	.val(function(sessionID){
		return sessions[sessionID].user_id;
	})
	.seq(retrieveProfile)
	.val(function(profileData){
		res.end(JSON.stringify({
			profile: profileData
		}));
	})
	.or(function(err){
		res.end(jsonError(err));
	});
}
​collectPostData(req)​ will return a asynquence 
​.val​ synchronous steps (take the data from the previous step)
​.seq(ValidateSession)​ <- async task (will return a new sequence)
when it completes: .val(function(sessionID){ return sessions[sessionID].user_id; })or the error is caught at ​.or​