Last active
February 9, 2017 01:08
-
-
Save CaseyLeask/7d1f570f61e1a16ee6605dc6664c2191 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var router = Router.create({ | |
routes, | |
location, | |
onAbort: function defaultAbortHandler(abortReason) { | |
reject(abortReason); | |
} | |
}); | |
router.run(function (Handler, State) { | |
(function() { | |
var data = {}; | |
return when.Promise.all(State.routes | |
.filter(route => route.handler.load_data) | |
.map(route => { | |
return route.load_data.fetch(State).then(d => { | |
data[route.name] = d; | |
}); | |
}))).then(() => data).then((data) => { | |
var appHtml = React.renderToString(<Handler data={data} />); | |
if (State.routes[State.routes.length-1].name == 'not-found') { | |
reject(new NotFoundResponse(appHtml)); | |
} else { | |
resolve(appHtml); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment