adjust renderToString context argument position

This commit is contained in:
Evan You 2017-04-20 10:15:41 +08:00
parent 2d50ac177b
commit 67d02fbf3f
3 changed files with 15 additions and 11 deletions

View File

@ -89,10 +89,10 @@ export function createBundleRendererCreator (createRenderer: () => Renderer) {
cb(err)
}).then(app => {
if (app) {
renderer.renderToString(app, (err, res) => {
renderer.renderToString(app, context, (err, res) => {
rewriteErrorTrace(err, maps)
cb(err, res)
}, context)
})
}
})
},

View File

@ -7,8 +7,8 @@ import { createRenderFunction } from './render'
import type { ClientManifest } from './template-renderer/index'
export type Renderer = {
renderToString: (component: Component, cb: (err: ?Error, res: ?string) => void) => void;
renderToStream: (component: Component) => stream$Readable;
renderToString: (component: Component, context: any, cb: any) => void;
renderToStream: (component: Component, context?: Object) => stream$Readable;
};
type RenderCache = {
@ -51,9 +51,13 @@ export function createRenderer ({
return {
renderToString (
component: Component,
done: (err: ?Error, res: ?string) => any,
context?: ?Object
context: any,
done: any
): void {
if (typeof context === 'function') {
done = context
context = {}
}
if (context) {
templateRenderer.bindRenderFns(context)
}
@ -76,7 +80,7 @@ export function createRenderer ({
renderToStream (
component: Component,
context?: ?Object
context?: Object
): stream$Readable {
if (context) {
templateRenderer.bindRenderFns(context)

View File

@ -54,7 +54,7 @@ describe('SSR: template option', () => {
renderer.renderToString(new Vue({
template: '<div>hi</div>'
}), (err, res) => {
}), context, (err, res) => {
expect(err).toBeNull()
expect(res).toContain(
`<html><head>${context.head}${context.styles}</head><body>` +
@ -63,7 +63,7 @@ describe('SSR: template option', () => {
`</body></html>`
)
done()
}, context)
})
})
it('renderToString with interpolation', done => {
@ -81,7 +81,7 @@ describe('SSR: template option', () => {
renderer.renderToString(new Vue({
template: '<div>hi</div>'
}), (err, res) => {
}), context, (err, res) => {
expect(err).toBeNull()
expect(res).toContain(
`<html><head>` +
@ -95,7 +95,7 @@ describe('SSR: template option', () => {
`</body></html>`
)
done()
}, context)
})
})
it('renderToStream', done => {