Home / Class/ RenderStream Class — vue Architecture

RenderStream Class — vue Architecture

Architecture documentation for the RenderStream class in render-stream.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  5f3e77fd_2395_2037_8fe2_ddb0a0a503a8["RenderStream"]
  1d39271f_a04e_7bb6_d848_5fe05aeadfba["render-stream.ts"]
  5f3e77fd_2395_2037_8fe2_ddb0a0a503a8 -->|defined in| 1d39271f_a04e_7bb6_d848_5fe05aeadfba
  ac9d0fc5_91e9_7ef4_b40f_5953b63312fa["constructor()"]
  5f3e77fd_2395_2037_8fe2_ddb0a0a503a8 -->|method| ac9d0fc5_91e9_7ef4_b40f_5953b63312fa
  ef9263a5_4bc9_37dd_6172_60f913bb3926["pushBySize()"]
  5f3e77fd_2395_2037_8fe2_ddb0a0a503a8 -->|method| ef9263a5_4bc9_37dd_6172_60f913bb3926
  f87747f3_6ceb_eb36_5e57_d014eb436990["tryRender()"]
  5f3e77fd_2395_2037_8fe2_ddb0a0a503a8 -->|method| f87747f3_6ceb_eb36_5e57_d014eb436990
  b5bbea85_4b9b_c154_6a8e_15e96d994434["tryNext()"]
  5f3e77fd_2395_2037_8fe2_ddb0a0a503a8 -->|method| b5bbea85_4b9b_c154_6a8e_15e96d994434
  4e0244b9_505f_366e_4bd9_e5e84c94da8e["_read()"]
  5f3e77fd_2395_2037_8fe2_ddb0a0a503a8 -->|method| 4e0244b9_505f_366e_4bd9_e5e84c94da8e

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 {

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