mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 10:29:18 -05:00
Initial refactoring so that watch from tsc follows the tsserver projects
This commit is contained in:
@@ -292,77 +292,4 @@ namespace ts.server {
|
||||
deleted(oldItems[oldIndex++]);
|
||||
}
|
||||
}
|
||||
|
||||
export function cleanExistingMap<T>(
|
||||
existingMap: Map<T>,
|
||||
onDeleteExistingValue: (key: string, existingValue: T) => void) {
|
||||
if (existingMap) {
|
||||
// Remove all
|
||||
existingMap.forEach((existingValue, key) => {
|
||||
existingMap.delete(key);
|
||||
onDeleteExistingValue(key, existingValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function mutateExistingMapWithNewSet<T>(
|
||||
existingMap: Map<T>, newMap: Map<true>,
|
||||
createNewValue: (key: string) => T,
|
||||
onDeleteExistingValue: (key: string, existingValue: T) => void
|
||||
): Map<T> {
|
||||
return mutateExistingMap(
|
||||
existingMap, newMap,
|
||||
/*createNewValue*/(key, _valueInNewMap) => createNewValue(key),
|
||||
onDeleteExistingValue,
|
||||
);
|
||||
}
|
||||
|
||||
export function mutateExistingMap<T, U>(
|
||||
existingMap: Map<T>, newMap: Map<U>,
|
||||
createNewValue: (key: string, valueInNewMap: U) => T,
|
||||
onDeleteExistingValue: (key: string, existingValue: T) => void,
|
||||
isSameValue?: (existingValue: T, valueInNewMap: U) => boolean,
|
||||
OnDeleteExistingMismatchValue?: (key: string, existingValue: T) => void,
|
||||
onSameExistingValue?: (existingValue: T, valueInNewMap: U) => void
|
||||
): Map<T> {
|
||||
// If there are new values update them
|
||||
if (newMap) {
|
||||
if (existingMap) {
|
||||
// Needs update
|
||||
existingMap.forEach((existingValue, key) => {
|
||||
const valueInNewMap = newMap.get(key);
|
||||
// Existing value - remove it
|
||||
if (valueInNewMap === undefined) {
|
||||
existingMap.delete(key);
|
||||
onDeleteExistingValue(key, existingValue);
|
||||
}
|
||||
// different value - remove it
|
||||
else if (isSameValue && !isSameValue(existingValue, valueInNewMap)) {
|
||||
existingMap.delete(key);
|
||||
OnDeleteExistingMismatchValue(key, existingValue);
|
||||
}
|
||||
else if (onSameExistingValue) {
|
||||
onSameExistingValue(existingValue, valueInNewMap);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Create new
|
||||
existingMap = createMap<T>();
|
||||
}
|
||||
|
||||
// Add new values that are not already present
|
||||
newMap.forEach((valueInNewMap, key) => {
|
||||
if (!existingMap.has(key)) {
|
||||
// New values
|
||||
existingMap.set(key, createNewValue(key, valueInNewMap));
|
||||
}
|
||||
});
|
||||
|
||||
return existingMap;
|
||||
}
|
||||
|
||||
cleanExistingMap(existingMap, onDeleteExistingValue);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user