Published
Edited
Aug 25, 2022
Insert cell
Insert cell
getset = import("@statewalker/getset")
Insert cell
Insert cell
Insert cell
Insert cell
{
// Generates a function updating user's last name and returning a copy of the original object:
const updateLastName = getset.newCloneSetter("userInfo.lastName");

const obj = {
userInfo: {
firstName: "John",
lastName: "Smith"
}
};
// Now we can use/reuse the generated method to update objects:
const newObj = updateLastName(obj, "SMITH");
return newObj;
}
Insert cell
Insert cell
{
const obj = {
userInfo: {
firstName: "John",
lastName: "Smith"
}
};
// Generate a function providing direct access to the user's first name:
const getter = getset.newGetter("userInfo.firstName");

// Now we can use/reuse the generated method to retrieve nested object fields:
const firstName = getter(obj);
return firstName;
}
Insert cell
Insert cell
{
// Generates a function updating user's last name without changing the hierarchy of objects:
const updateLastName = getset.newSetter("userInfo.lastName");

const obj = {
userInfo: {
firstName: "John",
lastName: "Smith"
}
};
// Now we can use/reuse the generated method to update objects:
const newObj = updateLastName(obj, "SMITH");
return { obj: JSON.stringify(obj), newObj: JSON.stringify(newObj) };
}
Insert cell
Insert cell
Insert cell
{
const obj = {
userInfo: {
firstName: "John",
lastName: "Smith"
}
};
return getset.get(obj, "userInfo.firstName");
}
Insert cell
Insert cell
{
const obj = {
userInfo: {
firstName: "John",
lastName: "Smith"
}
};
const newObj = getset.set(obj, "userInfo.lastName", "SMITH");
return newObj;
}

Insert cell
Insert cell
Insert cell
getset.buildCloneSetter("userInfo.firstName")
Insert cell
Insert cell
getset.buildGetter("userInfo.firstName")
Insert cell
Insert cell
getset.buildSetter("userInfo.firstName")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { toc } from "@nebrius/indented-toc"
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