@internal
(event: FrameValue.Event)
| 132 | |
| 133 | /** @internal */ |
| 134 | eventObserved(event: FrameValue.Event) { |
| 135 | // Update our value when an idle parent is changed, |
| 136 | // and enter the frameloop when a parent is resumed. |
| 137 | if (event.type == 'change') { |
| 138 | if (event.idle) { |
| 139 | this.advance() |
| 140 | } else { |
| 141 | this._active.add(event.parent) |
| 142 | this._start() |
| 143 | } |
| 144 | } |
| 145 | // Once all parents are idle, the `advance` method runs one more time, |
| 146 | // so we should avoid updating the `idle` status here. |
| 147 | else if (event.type == 'idle') { |
| 148 | this._active.delete(event.parent) |
| 149 | } |
| 150 | // Ensure our priority is greater than all parents, which means |
| 151 | // our value won't be updated until our parents have updated. |
| 152 | else if (event.type == 'priority') { |
| 153 | this.priority = toArray(this.source).reduce( |
| 154 | (highest: number, parent) => |
| 155 | Math.max(highest, (isFrameValue(parent) ? parent.priority : 0) + 1), |
| 156 | 0 |
| 157 | ) |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** Returns true for an idle source. */ |