MCPcopy
hub / github.com/streamlit/streamlit / ElementNode

Class ElementNode

frontend/lib/src/render-tree/ElementNode.ts:28–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26 * A leaf AppNode. Contains a single element to render.
27 */
28export class ElementNode implements AppNode {
29 public readonly element: Element
30
31 public readonly metadata: ForwardMsgMetadata
32
33 public readonly scriptRunId: string
34
35 public readonly fragmentId?: string
36
37 // The hash of the script that created this element.
38 public readonly activeScriptHash: string
39
40 // The hash of this element's payload for content-based deduplication.
41 public readonly elementHash?: string
42
43 /** Create a new ElementNode. */
44 public constructor(
45 element: Element,
46 metadata: ForwardMsgMetadata,
47 scriptRunId: string,
48 activeScriptHash: string,
49 fragmentId?: string,
50 elementHash?: string
51 ) {
52 this.element = element
53 this.metadata = metadata
54 this.scriptRunId = scriptRunId
55 this.activeScriptHash = activeScriptHash
56 this.fragmentId = fragmentId
57 this.elementHash = elementHash
58 }
59
60 /**
61 * Accept a visitor.
62 * @param visitor - The visitor to accept.
63 * @returns The result of the visitor's visitElementNode method.
64 * @example
65 * const visitor = new DebugVisitor()
66 * const result = elementNode.accept(visitor)
67 * console.log(result)
68 */
69 public accept<T>(visitor: AppNodeVisitor<T>): T {
70 return visitor.visitElementNode(this)
71 }
72
73 /**
74 * Returns a string representation of this ElementNode for debugging purposes.
75 * This method can be used to log or inspect the state of the node.
76 *
77 * @returns {string} A debug string describing this node.
78 */
79 public debug(): string {
80 return this.accept(new DebugVisitor())
81 }
82
83 public replaceTransientNodeWithSelf(node: TransientNode): AppNode {
84 if (node.scriptRunId !== this.scriptRunId) {
85 // This TransientNode was not defined in this script run, so we return the element node

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…