Home / File/ template-stream.ts — vue Source File

template-stream.ts — vue Source File

Architecture documentation for template-stream.ts, a typescript file in the vue codebase. 4 imports, 1 dependents.

File typescript ServerRenderer TemplateRenderer 4 imports 1 dependents 1 classes

Entity Profile

Dependency Diagram

graph LR
  93d70dd6_8b08_c5e1_f821_d322263718c1["template-stream.ts"]
  70b92f4c_021d_4bb1_d973_4e94bcad69f8["index.ts"]
  93d70dd6_8b08_c5e1_f821_d322263718c1 --> 70b92f4c_021d_4bb1_d973_4e94bcad69f8
  d44d125e_e152_100e_7961_1e6a838d88bf["parse-template.ts"]
  93d70dd6_8b08_c5e1_f821_d322263718c1 --> d44d125e_e152_100e_7961_1e6a838d88bf
  3957a359_b7cd_d9a7_574a_514933e95fd3["ParsedTemplate"]
  93d70dd6_8b08_c5e1_f821_d322263718c1 --> 3957a359_b7cd_d9a7_574a_514933e95fd3
  88745fde_3d83_000a_cda6_1c8dad22f755["stream"]
  93d70dd6_8b08_c5e1_f821_d322263718c1 --> 88745fde_3d83_000a_cda6_1c8dad22f755
  70b92f4c_021d_4bb1_d973_4e94bcad69f8["index.ts"]
  70b92f4c_021d_4bb1_d973_4e94bcad69f8 --> 93d70dd6_8b08_c5e1_f821_d322263718c1
  style 93d70dd6_8b08_c5e1_f821_d322263718c1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// const Transform = require("stream").Transform;
import type TemplateRenderer from './index'
import type { ParsedTemplate } from './parse-template'
import { Transform } from 'stream'

export default class TemplateStream extends Transform {
  started: boolean
  renderer: TemplateRenderer
  template: ParsedTemplate
  context: Record<string, any>
  inject: boolean

  constructor(
    renderer: TemplateRenderer,
    template: ParsedTemplate,
    context: Record<string, any>
  ) {
    super()
    this.started = false
    this.renderer = renderer
    this.template = template
    this.context = context || {}
    this.inject = renderer.inject
  }

  _transform(data: Buffer | string, encoding: string, done: Function) {
    if (!this.started) {
      this.emit('beforeStart')
      this.start()
    }
    this.push(data)
    done()
  }

  start() {
    this.started = true
    this.push(this.template.head(this.context))

    if (this.inject) {
      // inline server-rendered head meta information
      if (this.context.head) {
        this.push(this.context.head)
      }

      // inline preload/prefetch directives for initial/async chunks
      const links = this.renderer.renderResourceHints(this.context)
      if (links) {
        this.push(links)
      }

      // CSS files and inline server-rendered CSS collected by vue-style-loader
      const styles = this.renderer.renderStyles(this.context)
      if (styles) {
        this.push(styles)
      }
    }

    this.push(this.template.neck(this.context))
  }

  _flush(done: Function) {
    this.emit('beforeEnd')

    if (this.inject) {
      // inline initial store state
      const state = this.renderer.renderState(this.context)
      if (state) {
        this.push(state)
      }

      // embed scripts needed
      const scripts = this.renderer.renderScripts(this.context)
      if (scripts) {
        this.push(scripts)
      }
    }

    this.push(this.template.tail(this.context))
    done()
  }
}

Subdomains

Classes

Frequently Asked Questions

What does template-stream.ts do?
template-stream.ts is a source file in the vue codebase, written in typescript. It belongs to the ServerRenderer domain, TemplateRenderer subdomain.
What does template-stream.ts depend on?
template-stream.ts imports 4 module(s): ParsedTemplate, index.ts, parse-template.ts, stream.
What files import template-stream.ts?
template-stream.ts is imported by 1 file(s): index.ts.
Where is template-stream.ts in the architecture?
template-stream.ts is located at packages/server-renderer/src/template-renderer/template-stream.ts (domain: ServerRenderer, subdomain: TemplateRenderer, directory: packages/server-renderer/src/template-renderer).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free