pomodoro/server/render.jsx
Linus Miller 47ce0a2a33 Huge commit
- Update all deps
 - Apply midwest changes
 - Convert all templates to JSX
 - Preact instead of Marko
 - Babel & Eslint
2016-11-10 14:34:44 +01:00

32 lines
779 B
JavaScript

module.exports = function (Component, Master) {
const locals = Object.assign({}, this.app.locals, this.locals);
let preamble = '';
let html;
if (typeof Master === 'function') {
preamble = '<!doctype html>';
if (typeof Component === 'function') {
return this.send(preamble + (
<Master {...locals}>
<Component {...locals}/>
</Master>
));
}
Component = Master;
}
if (typeof Component !== 'function') {
throw new Error('Not a Component');
} else if (Component.prototype && Component.prototype.render) {
const instance = new Component(locals);
html = instance.render(instance.props, instance.state);
} else {
html = Component(locals);
}
this.send(preamble ? preamble + html : html);
};