()
| 108 | } |
| 109 | |
| 110 | export function endBatch() { |
| 111 | if (--globalState.inBatch === 0) { |
| 112 | runReactions() |
| 113 | // the batch is actually about to finish, all unobserving should happen here. |
| 114 | const list = globalState.pendingUnobservations |
| 115 | for (let i = 0; i < list.length; i++) { |
| 116 | const observable = list[i] |
| 117 | observable.isPendingUnobservation = false |
| 118 | if (observable.observers_.size === 0) { |
| 119 | if (observable.isBeingObserved) { |
| 120 | // if this observable had reactive observers, trigger the hooks |
| 121 | observable.isBeingObserved = false |
| 122 | observable.onBUO() |
| 123 | } |
| 124 | if (observable instanceof ComputedValue) { |
| 125 | // computed values are automatically teared down when the last observer leaves |
| 126 | // this process happens recursively, this computed might be the last observabe of another, etc.. |
| 127 | observable.suspend_() |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | globalState.pendingUnobservations = [] |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | export function reportObserved(observable: IObservable): boolean { |
| 136 | checkIfStateReadsAreAllowed(observable) |
no test coverage detected
searching dependent graphs…