Public
Edited
Jan 17, 2024
Insert cell
Insert cell
Insert cell
firstName = signia.atom("firstName", "David")
Insert cell
lastName = signia.atom("lastName", "Bowie")
Insert cell
fullName = signia.computed("fullName", () => {
return `${firstName.value} ${lastName.value}`;
})
Insert cell
firstName.set("John")
Insert cell
firstName.update((value) => value.toUpperCase())
Insert cell
signia.transact((rollback) => {
firstName.set("John");
lastName.set("Lennon");
rollback();
})
Insert cell
fullName.value
Insert cell
firstName.lastChangedEpoch
Insert cell
fullName.lastChangedEpoch
Insert cell
// [[{op:"replace",path:[1],value:"Abhiti"}]]
data = {
immer.enablePatches();

const names = signia.atom("names", ["Bob", "Alice"], {
historyLength: 10,
computeDiff: (prev, next) => {
console.log(prev, next);
return immer.produceWithPatches(prev, (draft) => {
return next;
})[1];
}
});

const startEpoch = names.lastChangedEpoch;
names.set(["Bob", "Abhiti"]);
return JSON.stringify(names.getDiffSince(startEpoch));
}
Insert cell
{
const prev = ["bob", "alice"];
const next = ["bob", "abhiti"];

immer.enablePatches();
const diffs = immer.produceWithPatches(prev, (draft) => next);
return diffs.slice(1).map((it) => JSON.stringify(it).replaceAll('"', "'"));
}
Insert cell
{
const prev = ["bob", "alice"];
const next = ["bob", "abhiti"];

const diffs = fastArrayDiff.getPatch(prev, next);
return diffs.map((it) => JSON.stringify(it).replaceAll('"', "'"));
}
Insert cell
Insert cell
fastArrayDiff = import("https://cdn.jsdelivr.net/npm/fast-array-diff/+esm")
Insert cell
immerVersion = "7.0.15" // latest: 10.0.3
Insert cell
Insert cell
immer = import(
`https://cdn.jsdelivr.net/npm/immer@9.0.21/dist/immer.cjs.development.js/+esm`
)
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more