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. 3 imports, 1 dependents.

File typescript ServerRenderer BundleRenderer 3 imports 1 dependents 1 classes

Entity Profile

Dependency Diagram

graph LR
  7c3caf9f_7ed4_b48a_352b_1ad68589eac6["template-stream.ts"]
  dd60f8d3_0510_6c88_43e7_0031a6d72263["index.ts"]
  7c3caf9f_7ed4_b48a_352b_1ad68589eac6 --> dd60f8d3_0510_6c88_43e7_0031a6d72263
  1ca1acca_d1ee_7141_7af0_637ac6a95f5f["parse-template.ts"]
  7c3caf9f_7ed4_b48a_352b_1ad68589eac6 --> 1ca1acca_d1ee_7141_7af0_637ac6a95f5f
  7aef85ef_4754_53fb_5d94_f8411adf9a0a["stream"]
  7c3caf9f_7ed4_b48a_352b_1ad68589eac6 --> 7aef85ef_4754_53fb_5d94_f8411adf9a0a
  dd60f8d3_0510_6c88_43e7_0031a6d72263["index.ts"]
  dd60f8d3_0510_6c88_43e7_0031a6d72263 --> 7c3caf9f_7ed4_b48a_352b_1ad68589eac6
  style 7c3caf9f_7ed4_b48a_352b_1ad68589eac6 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

Dependencies

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, BundleRenderer subdomain.
What does template-stream.ts depend on?
template-stream.ts imports 3 module(s): 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: BundleRenderer, 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