Public
Edited
Mar 3, 2023
Insert cell
Insert cell
Insert cell
Insert cell
getDiff(before)(after)
Insert cell
Insert cell
Insert cell
renderer = () => {
const toString = (value) =>
!isPrimitive(value) ? "complex value" : `'${value}'`;

const makeText = (node, parentKey) => {
if (node.type === "added") {
const title = !isPrimitive(node.newValue) ? "" : "value ";
const newValue = toString(node.newValue);
return `Property '${parentKey}${node.key}' was added with ${title}${newValue}`;
}
if (node.type === "removed") {
return `Property '${parentKey}${node.key}' was removed`;
}
if (node.type === "changed") {
const oldValue = toString(node.oldValue);
const newValue = toString(node.newValue);
return `Property '${parentKey}${node.key}' was updated. From ${oldValue} to ${newValue}`;
}
if (node.type === "unchanged") {
return "";
}
return node.children
.map((item) => makeText(item, `${parentKey}${node.key}.`))
.filter((x) => x !== "")
.join("\n");
};
// export const plainRenderer
return (ast) =>
`${ast
.map((node) => makeText(node, ""))
.filter((x) => x !== "")
.join("\n")}\n`;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more