| 27 | * A container AppNode that holds children. |
| 28 | */ |
| 29 | export class BlockNode implements AppNode { |
| 30 | public readonly children: AppNode[] |
| 31 | |
| 32 | public readonly deltaBlock: BlockProto |
| 33 | |
| 34 | public readonly scriptRunId: string |
| 35 | |
| 36 | public readonly fragmentId?: string |
| 37 | |
| 38 | public readonly deltaMsgReceivedAt?: number |
| 39 | |
| 40 | // The hash of the script that created this block. |
| 41 | public readonly activeScriptHash: string |
| 42 | |
| 43 | public constructor( |
| 44 | activeScriptHash: string, |
| 45 | children?: AppNode[], |
| 46 | deltaBlock?: BlockProto, |
| 47 | scriptRunId?: string, |
| 48 | fragmentId?: string, |
| 49 | deltaMsgReceivedAt?: number |
| 50 | ) { |
| 51 | this.activeScriptHash = activeScriptHash |
| 52 | this.children = children ?? [] |
| 53 | this.deltaBlock = deltaBlock ?? new BlockProto({}) |
| 54 | this.scriptRunId = scriptRunId ?? NO_SCRIPT_RUN_ID |
| 55 | this.fragmentId = fragmentId |
| 56 | this.deltaMsgReceivedAt = deltaMsgReceivedAt |
| 57 | } |
| 58 | |
| 59 | /** True if this Block has no children. */ |
| 60 | public get isEmpty(): boolean { |
| 61 | return this.children.length === 0 |
| 62 | } |
| 63 | |
| 64 | public replaceTransientNodeWithSelf(node: TransientNode): AppNode { |
| 65 | if (node.scriptRunId !== this.scriptRunId) { |
| 66 | // This TransientNode was not defined in this script run, so we return the block node |
| 67 | // to replace everything |
| 68 | return this |
| 69 | } |
| 70 | |
| 71 | // It's essentially an empty transient node, so we return the block node |
| 72 | if (node.transientNodes.length === 0) { |
| 73 | return this |
| 74 | } |
| 75 | |
| 76 | // At this point, we should clear the transient nodes that are stale |
| 77 | const newTransientNodes = node.updateTransientNodes( |
| 78 | element => |
| 79 | element.accept(new ClearStaleNodeVisitor(this.scriptRunId)) as |
| 80 | | ElementNode |
| 81 | | undefined |
| 82 | ) |
| 83 | |
| 84 | // The resulting transient node is empty, so we return this node |
| 85 | if (newTransientNodes.length === 0) { |
| 86 | return this |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…