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

Function updateItemIndexWithValue

core/queryIndex.ts:107–131  ·  view source on GitHub ↗
(
    entity: TargetEntity,
    indexValue: TargetValue
  )

Source from the content-addressed store, hash-verified

105 }
106
107 function updateItemIndexWithValue(
108 entity: TargetEntity,
109 indexValue: TargetValue
110 ) {
111 // Item might already be indexed somewhere
112 const currentIndexList = currentItemIndexMap.get(entity);
113 // Get where it should be indexed now
114 const targetIndexList = observableMapGetOrCreate(
115 observableIndex,
116 indexValue,
117 () => observable.array()
118 );
119
120 // There is no need to do anything - indexed value did not change
121 if (currentIndexList === targetIndexList) return;
122
123 runInAction(() => {
124 if (currentIndexList) {
125 currentIndexList.remove(entity);
126 }
127 targetIndexList.push(entity);
128
129 currentItemIndexMap.set(entity, targetIndexList);
130 });
131 }
132
133 function updateItemIndex(entity: TargetEntity) {
134 const indexValue = getCurrentIndexValue(entity);

Callers 2

updateItemIndexFunction · 0.85

Calls 2

observableMapGetOrCreateFunction · 0.85
removeMethod · 0.65

Tested by

no test coverage detected