Skip to content

Commit 2a86f10

Browse files
author
DominusVilicus
committed
added capability for async render function for template
1 parent 05f0224 commit 2a86f10

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Diff for: src/server/template-renderer/index.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ export default class TemplateRenderer {
5555
this.inject = options.inject !== false
5656
// if no template option is provided, the renderer is created
5757
// as a utility object for rendering assets like preload links and scripts.
58-
this.parsedTemplate = options.template
59-
? parseTemplate(options.template)
60-
: null
58+
59+
let template = options.template
60+
61+
this.parsedTemplate = template
62+
? typeof template === 'function'
63+
? template : parseTemplate(template)
64+
: null;
6165

6266
// function used to serialize initial state JSON
6367
this.serialize = options.serializer || (state => {
@@ -89,12 +93,16 @@ export default class TemplateRenderer {
8993
}
9094

9195
// render synchronously given rendered app content and render context
92-
renderSync (content: string, context: ?Object) {
96+
async render (content: string, context: ?Object) {
9397
const template = this.parsedTemplate
9498
if (!template) {
95-
throw new Error('renderSync cannot be called without a template.')
99+
throw new Error('render cannot be called without a template.')
96100
}
97101
context = context || {}
102+
103+
//if the template is a function, just call the template and return
104+
if(typeof template === 'function') return template(content, context)
105+
98106
if (this.inject) {
99107
return (
100108
template.head(context) +

0 commit comments

Comments
 (0)