Skip to content

Commit 2ac581b

Browse files
HerringtonDarkholmeyyx990803
authored andcommitted
SSR: eliminate closure in render.js implementation
eliminate closure fix multiple render instances and memory leakage fix eslint magically fix flow typing add multiple render stream test
1 parent b51b9ea commit 2ac581b

File tree

9 files changed

+245
-171
lines changed

9 files changed

+245
-171
lines changed

flow/options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ declare type ComponentOptions = {
5757
_propKeys?: Array<string>;
5858
_parentVnode?: VNode;
5959
_parentListeners?: ?Object;
60-
_renderChildren?: ?VNodeChildren
60+
_renderChildren?: ?VNodeChildren;
61+
_componentTag: ?string;
62+
_scopeId: ?string;
6163
}
6264

6365
declare type PropOptions = {

flow/ssr.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
declare type ComponentWithCacheContext = {
2+
type: 'ComponentWithCache';
3+
bufferIndex: number;
4+
buffer: Array<string>;
5+
key: string;
6+
}
7+
8+
declare type ElementContext = {
9+
type: 'Element';
10+
children: Array<VNode>;
11+
rendered: number;
12+
endTag: string;
13+
total: number;
14+
}
15+
16+
declare type ComponentContext = {
17+
type: 'Component';
18+
prevActive: Component;
19+
}
20+
21+
declare type RenderState = ComponentContext | ComponentWithCacheContext | ElementContext

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"eslint-loader": "^1.3.0",
6868
"eslint-plugin-flowtype": "^2.16.0",
6969
"eslint-plugin-vue": "^1.0.0",
70-
"flow-bin": "^0.32.0",
70+
"flow-bin": "^0.33.0",
7171
"he": "^1.1.0",
7272
"http-server": "^0.9.0",
7373
"jasmine": "2.4.x",

src/compiler/codegen/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ function genElement (el: ASTElement): string {
5353
// component or element
5454
let code
5555
if (el.component) {
56-
code = genComponent(el)
56+
code = genComponent(el.component, el)
5757
} else {
58-
const data = genData(el)
58+
const data = el.plain ? undefined : genData(el)
59+
5960
const children = el.inlineTemplate ? null : genChildren(el)
6061
code = `_h('${el.tag}'${
6162
data ? `,${data}` : '' // data
@@ -95,11 +96,7 @@ function genFor (el: any): string {
9596
'})'
9697
}
9798

98-
function genData (el: ASTElement): string | void {
99-
if (el.plain) {
100-
return
101-
}
102-
99+
function genData (el: ASTElement): string {
103100
let data = '{'
104101

105102
// directives first.
@@ -229,9 +226,10 @@ function genSlot (el: ASTElement): string {
229226
: `_t(${slotName})`
230227
}
231228

232-
function genComponent (el: any): string {
229+
// componentName is el.component, take it as argument to shun flow's pessimistic refinement
230+
function genComponent (componentName, el): string {
233231
const children = el.inlineTemplate ? null : genChildren(el)
234-
return `_h(${el.component},${genData(el)}${
232+
return `_h(${componentName},${genData(el)}${
235233
children ? `,${children}` : ''
236234
})`
237235
}

src/core/util/props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function assertProp (
126126
*/
127127
function assertType (value: any, type: Function): {
128128
valid: boolean,
129-
expectedType: string
129+
expectedType: ?string
130130
} {
131131
let valid
132132
let expectedType = getType(type)

src/server/render-stream.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import { createWriteFunction } from './write'
1313

1414
export default class RenderStream extends stream.Readable {
1515
buffer: string;
16-
render: Function;
16+
render: (write: Function, done: Function) => void;
1717
expectedSize: number;
18-
stackDepth: number;
1918
write: Function;
2019
next: Function;
2120
end: Function;
@@ -26,7 +25,6 @@ export default class RenderStream extends stream.Readable {
2625
this.buffer = ''
2726
this.render = render
2827
this.expectedSize = 0
29-
this.stackDepth = 0
3028

3129
this.write = createWriteFunction((text, next) => {
3230
const n = this.expectedSize

0 commit comments

Comments
 (0)