RenderStream Class — vue Architecture
Architecture documentation for the RenderStream class in render-stream.ts from the vue codebase.
Entity Profile
Dependency Diagram
graph TD 60ba4fed_c502_859c_60b1_5ab9b57882ca["RenderStream"] f3e6847d_8ff5_35b6_8fd0_7c2d8f08f289["render-stream.ts"] 60ba4fed_c502_859c_60b1_5ab9b57882ca -->|defined in| f3e6847d_8ff5_35b6_8fd0_7c2d8f08f289 ec62e370_b17a_a955_cb10_fe4626afcaf0["constructor()"] 60ba4fed_c502_859c_60b1_5ab9b57882ca -->|method| ec62e370_b17a_a955_cb10_fe4626afcaf0 9142a816_c281_34f1_d187_c42a71e9ebc2["pushBySize()"] 60ba4fed_c502_859c_60b1_5ab9b57882ca -->|method| 9142a816_c281_34f1_d187_c42a71e9ebc2 5424efdc_7dd2_a107_0b02_df960b12b9bb["tryRender()"] 60ba4fed_c502_859c_60b1_5ab9b57882ca -->|method| 5424efdc_7dd2_a107_0b02_df960b12b9bb f1eef107_ac43_15e5_0802_999cd0990503["tryNext()"] 60ba4fed_c502_859c_60b1_5ab9b57882ca -->|method| f1eef107_ac43_15e5_0802_999cd0990503 26f93250_b4a7_4186_f2ca_6e7705f6c0d6["_read()"] 60ba4fed_c502_859c_60b1_5ab9b57882ca -->|method| 26f93250_b4a7_4186_f2ca_6e7705f6c0d6
Relationship Graph
Source Code
packages/server-renderer/src/render-stream.ts lines 15–100
export default class RenderStream extends Readable {
buffer: string
render: (write: Function, done: Function) => void
expectedSize: number
write: Function
//@ts-expect-error
next: Function
end: Function
//@ts-expect-error
done: boolean
constructor(render: Function) {
super()
this.buffer = ''
//@ts-expect-error
this.render = render
this.expectedSize = 0
this.write = createWriteFunction(
(text, next) => {
const n = this.expectedSize
this.buffer += text
if (this.buffer.length >= n) {
this.next = next
this.pushBySize(n)
return true // we will decide when to call next
}
return false
},
err => {
this.emit('error', err)
}
)
this.end = () => {
this.emit('beforeEnd')
// the rendering is finished; we should push out the last of the buffer.
this.done = true
this.push(this.buffer)
}
}
pushBySize(n: number) {
const bufferToPush = this.buffer.substring(0, n)
this.buffer = this.buffer.substring(n)
this.push(bufferToPush)
}
tryRender() {
try {
this.render(this.write, this.end)
} catch (e) {
this.emit('error', e)
}
}
tryNext() {
try {
this.next()
} catch (e) {
this.emit('error', e)
}
}
_read(n: number) {
this.expectedSize = n
// it's possible that the last chunk added bumped the buffer up to > 2 * n,
// which means we will need to go through multiple read calls to drain it
// down to < n.
if (isTrue(this.done)) {
this.push(null)
return
}
if (this.buffer.length >= n) {
this.pushBySize(n)
return
}
if (isUndef(this.next)) {
// start the rendering chain.
this.tryRender()
} else {
Domain
Source
Frequently Asked Questions
What is the RenderStream class?
RenderStream is a class in the vue codebase, defined in packages/server-renderer/src/render-stream.ts.
Where is RenderStream defined?
RenderStream is defined in packages/server-renderer/src/render-stream.ts at line 15.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free