MCPcopy Create free account
hub / github.com/clientdb/clientdb / registerEntityForDerievedChanges

Function registerEntityForDerievedChanges

core/queryIndex.ts:183–202  ·  view source on GitHub ↗
(entity: TargetEntity)

Source from the content-addressed store, hash-verified

181 const entityDerievationWatching = new WeakMap<TargetEntity, () => void>();
182
183 function registerEntityForDerievedChanges(entity: TargetEntity) {
184 updateItemIndex(entity);
185 if (entityDerievationWatching.has(entity)) {
186 // Should not happen, but if does - could cause big bottlenecks
187 console.warn("Bad state");
188 return;
189 }
190
191 // Observe entity key using mobx
192 // Note - this is lazy so will not be called initially until actual change happens
193 const stop = observe(entity, key, (change) => {
194 // We can use updateItemIndexWithValue as we know new value in change mobx event. This saves us computing the value twice if it is not cached.
195 updateItemIndexWithValue(entity, change.newValue as TargetValue);
196 });
197
198 cleanup.next = stop;
199
200 // Save cleanup and mark entity as already observed
201 entityDerievationWatching.set(entity, stop);
202 }
203
204 function stopWatchingEntityForDerievedChange(entity: TargetEntity) {
205 removeItemFromIndex(entity);

Callers 1

handleUpdateRequestFunction · 0.85

Calls 2

updateItemIndexFunction · 0.85
updateItemIndexWithValueFunction · 0.85

Tested by

no test coverage detected