(entity: TargetEntity)
| 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); |
no test coverage detected