MCPcopy
hub / github.com/streamlit/streamlit / TransientNode

Class TransientNode

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

Source from the content-addressed store, hash-verified

26 */
27
28export class TransientNode implements AppNode {
29 readonly anchor?: AppNode
30 readonly transientNodes: ElementNode[]
31 readonly scriptRunId: string
32 readonly deltaMsgReceivedAt?: number
33 readonly fragmentId?: string
34 readonly activeScriptHash?: string
35
36 constructor(
37 scriptRunId: string,
38 anchor?: AppNode,
39 transientNodes?: ElementNode[],
40 deltaMsgReceivedAt?: number
41 ) {
42 this.scriptRunId = scriptRunId
43 this.anchor = anchor
44 this.transientNodes = transientNodes ?? []
45 this.deltaMsgReceivedAt = deltaMsgReceivedAt ?? Date.now()
46
47 // We explicitly set these to undefined because transient nodes
48 // are not associated with a fragment or a script hash directly.
49 // The anchor node will have the fragmentId and activeScriptHash.
50 this.fragmentId = undefined
51 this.activeScriptHash = undefined
52 }
53
54 /**
55 * Updates the transient nodes by applying a function to each transient node.
56 * If the function returns undefined, the transient node is removed from the list.
57 * @param update - A function that takes an ElementNode and returns an ElementNode or undefined.
58 * @returns A new array of transient nodes.
59 */
60 public updateTransientNodes(
61 update: (node: ElementNode) => ElementNode | undefined
62 ): ElementNode[] {
63 const newTransientNodes: ElementNode[] = []
64 this.transientNodes.forEach(element => {
65 const updatedElement = update(element)
66 if (updatedElement) {
67 newTransientNodes.push(updatedElement)
68 }
69 })
70
71 return newTransientNodes
72 }
73
74 accept<T>(visitor: AppNodeVisitor<T>): T {
75 return visitor.visitTransientNode(this)
76 }
77
78 public debug(): string {
79 return this.accept(new DebugVisitor())
80 }
81
82 // Combine the information of the node with the updated information
83 // of *this* node
84 public replaceTransientNodeWithSelf(node: TransientNode): AppNode {
85 if (

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…