| 260 | * Collection Node which is copied on write. |
| 261 | */ |
| 262 | export class ElementNode<T> extends BaseNode<T> { |
| 263 | nodeType = 8; // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions) |
| 264 | node: CollectionNode<T> | null; |
| 265 | isMutated = true; |
| 266 | private _index: number = 0; |
| 267 | isHidden = false; |
| 268 | |
| 269 | constructor(type: string, ownerDocument: Document<T, any>) { |
| 270 | super(ownerDocument); |
| 271 | this.node = null; |
| 272 | } |
| 273 | |
| 274 | get index(): number { |
| 275 | return this._index; |
| 276 | } |
| 277 | |
| 278 | set index(index: number) { |
| 279 | this._index = index; |
| 280 | this.ownerDocument.markDirty(this); |
| 281 | } |
| 282 | |
| 283 | get level(): number { |
| 284 | if (this.parentNode instanceof ElementNode) { |
| 285 | return this.parentNode.level + (this.parentNode.node?.type === 'item' ? 1 : 0); |
| 286 | } |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Lazily gets a mutable instance of a Node. If the node has already |
| 293 | * been cloned during this update cycle, it just returns the existing one. |
| 294 | */ |
| 295 | private getMutableNode(): Mutable<CollectionNode<T>> | null { |
| 296 | if (this.node == null) { |
| 297 | return null; |
| 298 | } |
| 299 | |
| 300 | if (!this.isMutated) { |
| 301 | this.node = this.node.clone(); |
| 302 | this.isMutated = true; |
| 303 | } |
| 304 | |
| 305 | this.ownerDocument.markDirty(this); |
| 306 | return this.node; |
| 307 | } |
| 308 | |
| 309 | updateNode(): void { |
| 310 | let nextSibling = this.nextVisibleSibling; |
| 311 | let node = this.getMutableNode(); |
| 312 | if (node == null) { |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | node.index = this.index; |
| 317 | node.level = this.level; |
| 318 | node.parentKey = |
| 319 | this.parentNode instanceof ElementNode ? (this.parentNode.node?.key ?? null) : null; |
nothing calls this directly
no outgoing calls
no test coverage detected