in packages/graph-explorer/src/core/StateProvider/userPreferences.ts [140:167]
await set(userStylingAtom, async prevUserStyling => {
let newNodes = Array.from((await prevUserStyling).vertices ?? []);
const existingIndex = newNodes.findIndex(
node => node.type === nodeType
);
const prev = existingIndex !== -1 ? newNodes[existingIndex] : undefined;
const newValue = typeof update === "function" ? update(prev) : update;
if (newValue === RESET || !newValue) {
// Remove the entry from user styles
newNodes = newNodes.filter(node => node.type !== nodeType);
} else if (existingIndex === -1) {
// Add it because it doesn't exist
newNodes.push(newValue);
} else {
// Replace the existing entry
newNodes[existingIndex] = {
...newNodes[existingIndex],
...newValue,
};
}
return {
...prev,
vertices: newNodes,
};
});