MCPcopy
hub / github.com/mobxjs/mobx / endBatch

Function endBatch

packages/mobx/src/core/observable.ts:110–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

108}
109
110export 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
135export function reportObserved(observable: IObservable): boolean {
136 checkIfStateReadsAreAllowed(observable)

Callers 13

defineProperty_Method · 0.85
delete_Method · 0.85
initObservableFunction · 0.85
runReaction_Method · 0.85
trackMethod · 0.85
disposeMethod · 0.85
getMethod · 0.85
reportChangedMethod · 0.85
_endActionFunction · 0.85
transactionFunction · 0.85

Calls 3

suspend_Method · 0.80
runReactionsFunction · 0.70
onBUOMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…