Better debugging experience with user profile

This commit is contained in:
garronej
2021-11-07 20:17:14 +01:00
parent 59386241b4
commit 747248454d
7 changed files with 97 additions and 37 deletions

View File

@ -1,9 +1,38 @@
import { assert } from "tsafe/assert";
import { is } from "tsafe/is";
function deepClone<T>(src: T): T {
const generateId = (() => {
const prefix = "xIfKdLsIIdJdLdOeJqePe";
let counter = 0;
return () => `${prefix}${counter++}`;
})();
const map = new Map<string, Function>();
return JSON.parse(
JSON.stringify(src, (...[, value]) => {
if (typeof value === "function") {
const id = generateId();
map.set(id, value);
return id;
}
return value;
}),
(...[, value]) => (typeof value === "string" && map.has(value) ? map.get(value) : value),
);
}
//Warning: Be mindful that because of array this is not idempotent.
export function deepAssign(params: { target: Record<string, unknown>; source: Record<string, unknown> }) {
const { target, source } = params;
const { target } = params;
const source = deepClone(params.source);
Object.keys(source).forEach(key => {
var dereferencedSource = source[key];