journey/server/render.js
2017-02-23 19:29:58 +01:00

33 lines
710 B
JavaScript

'use strict';
const { h } = require('jsx-node');
module.exports = function (Component, Master) {
const locals = Object.assign({ query: this.req.query }, this.app.locals, this.locals);
let html;
if (typeof Master === 'function') {
if (typeof Component === 'function') {
return this.send(
h(Master, locals,
h(Component, locals)
)
);
}
Component = Master;
}
if (typeof Component !== 'function') {
throw new Error('Not a Component');
} else if (Component.prototype && Component.prototype.render) {
const i = new Component(locals);
html = i.render(i.props, i.state);
} else {
html = Component(locals);
}
this.send(html);
};