File tree 1 file changed +13
-5
lines changed
src/server/template-renderer
1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -55,9 +55,13 @@ export default class TemplateRenderer {
55
55
this . inject = options . inject !== false
56
56
// if no template option is provided, the renderer is created
57
57
// 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 ;
61
65
62
66
// function used to serialize initial state JSON
63
67
this . serialize = options . serializer || ( state => {
@@ -89,12 +93,16 @@ export default class TemplateRenderer {
89
93
}
90
94
91
95
// render synchronously given rendered app content and render context
92
- renderSync ( content : string , context : ?Object ) {
96
+ async render ( content : string , context : ?Object ) {
93
97
const template = this . parsedTemplate
94
98
if ( ! template ) {
95
- throw new Error ( 'renderSync cannot be called without a template.' )
99
+ throw new Error ( 'render cannot be called without a template.' )
96
100
}
97
101
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
+
98
106
if ( this . inject ) {
99
107
return (
100
108
template . head ( context ) +
You can’t perform that action at this time.
0 commit comments