writing koa middleware for fluxible-router (async executeAction) -
i'm trying use koa fluxible-router. express examples use similar pattern use send() directly navigateaction.
react.rendertostring() right props hen called in executeaction context.
'use strict'; var react = require('react'); var app = require('./app'); var navigateaction = require('fluxible-router').navigateaction; function render() { return function *render(next) { var context = app.createcontext( { req: this.request , xhrcontext: { _csrf: 'pino' } } ); var html = null; context.executeaction(navigateaction, { method: this.request.method , url: this.request.url }, function (err) { // function executed asyncronously console.log('1'); var html = react.rendertostring(context.createelement()); }); this.body = html; console.log('2'); yield* next; } } module.exports = render;
the way i've found props populated run rendertostring() inside executeaction() executed asyncronously, console.log('2') executed before console.log('1') , returned body null.
i'm not aware of way wait rendertostring nor way run rendertostring() in right context.
thanks
this way it
https://gist.github.com/cesarandreu/03f6c584a40c62812deb
or yield context.executeaction(...)
Comments
Post a Comment