* Push a new operation to the tail of the list.
(op: OpT | Array<OpT>)
| 87 | * Push a new operation to the tail of the list. |
| 88 | */ |
| 89 | push(op: OpT | Array<OpT>): void { |
| 90 | if (Array.isArray(op)) { |
| 91 | for (const o of op) { |
| 92 | this.push(o); |
| 93 | } |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | OpList.assertIsNotEnd(op); |
| 98 | OpList.assertIsUnowned(op); |
| 99 | |
| 100 | op.debugListId = this.debugListId; |
| 101 | |
| 102 | // The old "previous" node (which might be the head, if the list is empty). |
| 103 | const oldLast = this.tail.prev!; |
| 104 | |
| 105 | // Insert `op` following the old last node. |
| 106 | op.prev = oldLast; |
| 107 | oldLast.next = op; |
| 108 | |
| 109 | // Connect `op` with the list tail. |
| 110 | op.next = this.tail; |
| 111 | this.tail.prev = op; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Prepend one or more nodes to the start of the list. |