Fix undo / redo

This commit is contained in:
Marcel Mraz 2025-04-29 15:27:37 +02:00
parent 0c21f1ae07
commit eb9b6ac837
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
5 changed files with 118 additions and 70 deletions

View file

@ -1233,3 +1233,27 @@ export const sizeOf = (
? value.size
: Object.keys(value).length;
};
/**
* Deep freeze an object to prevent any modifications to the object or its nested properties.
*/
export const deepFreeze = <T>(obj: T): T => {
// Return if obj is null or not an object
if (obj === null || typeof obj !== "object") {
return obj;
}
// Freeze the object itself
Object.freeze(obj);
// Freeze all properties
Object.getOwnPropertyNames(obj).forEach((prop) => {
const value = (obj as any)[prop];
if (value && typeof value === "object") {
deepFreeze(value);
}
});
return obj;
};