MCPcopy
hub / github.com/webpack/webpack / startUpdate

Method startUpdate

lib/util/LazyBucketSortedSet.js:187–245  ·  view source on GitHub ↗

* Begins an in-place update for an item and returns a completion callback * that can either reinsert it under a new key or remove it entirely. * @param {T} item to be updated item * @returns {(remove?: true) => void} finish update

(item)

Source from the content-addressed store, hash-verified

185 * @returns {(remove?: true) => void} finish update
186 */
187 startUpdate(item) {
188 if (this._unsortedItems.has(item)) {
189 return (remove) => {
190 if (remove) {
191 this._unsortedItems.delete(item);
192 this.size--;
193 }
194 };
195 }
196 const key = this._getKey(item);
197 if (this._leaf) {
198 const oldEntry = /** @type {SortableSet<T>} */ (this._map.get(key));
199 return (remove) => {
200 if (remove) {
201 this.size--;
202 oldEntry.delete(item);
203 if (oldEntry.size === 0) {
204 this._deleteKey(key);
205 }
206 return;
207 }
208 const newKey = this._getKey(item);
209 if (key === newKey) {
210 // This flags the sortable set as unordered
211 oldEntry.add(item);
212 } else {
213 oldEntry.delete(item);
214 if (oldEntry.size === 0) {
215 this._deleteKey(key);
216 }
217 this._addInternal(newKey, item);
218 }
219 };
220 }
221 const oldEntry =
222 /** @type {LazyBucketSortedSet<T, K>} */
223 (this._map.get(key));
224 const finishUpdate = oldEntry.startUpdate(item);
225 return (remove) => {
226 if (remove) {
227 this.size--;
228 finishUpdate(true);
229 if (oldEntry.size === 0) {
230 this._deleteKey(key);
231 }
232 return;
233 }
234 const newKey = this._getKey(item);
235 if (key === newKey) {
236 finishUpdate();
237 } else {
238 finishUpdate(true);
239 if (oldEntry.size === 0) {
240 this._deleteKey(key);
241 }
242 this._addInternal(newKey, item);
243 }
244 };

Callers 1

applyMethod · 0.95

Calls 6

_deleteKeyMethod · 0.95
_addInternalMethod · 0.95
hasMethod · 0.45
deleteMethod · 0.45
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected