Public
Edited
Dec 25, 2022
Insert cell
Insert cell
{
const Items = component(({ children }) => H.ul(children));

const Item = component(({ name, value }) =>
H.li(
"ITEMxxx: name:",
name,
" value:",
value,
new DebugEffector(
value,
() => console.log("PRE"),
() => console.log("POST")
)
)
);

const List = component(({ items }) =>
H.div(
"List",
Items(
$(items).map(({ name, value, items }) =>
H.li(
"ListItem:",
debug(
$(items).map(({ name, value }) =>
H.div("EXX", Item({ name, value }))
),
"items.map"
)
)
)
)
)
);
const items = [{ name: "AName", value: "BValue" }];
return render(List, {
items: [
{ name: "A", items },
{ name: "B", items }
]
});
}
Insert cell
component(({ name, value }) =>
H.li(
"ITEM: name:",
name,
" value:",
value,
new DebugEffector(
value,
() => console.log("PRE"),
() => console.log("POST")
)
)
).effector.mapping
Insert cell
{
return null;
const GraphNode = component(({ x, y, dx, dy, width, height, dragging }) => {
// TODO: We should have a cell for the current components (which we can send signals)
// TODO: Lifecycle events, ie. mount, unmount, etc
return H.g(
H.foreignObject(
{
x,
/*: $([x, dx], ([x, dx]) => {
console.log("XXX", (x || 0) + (dx || 0));
return (x || 0) + (dx || 0);
})*/ y,
width,
height,
onMouseDown:
(event, path) =>
({ dragging, x, y }, update) => {
console.log("ORIGINAL", { x, y, path });
//off(window.document.body, dragging?.handlers);
const context = {
xo: event.pageX,
yo: event.pageY
};
const handlers = {
mousemove: (event) => {
const dx = event.pageX - context.xo;
const dy = event.pageY - context.yo;
//console.log("UPDATE", { dx, dy, update });
return update({ dx, dy });
},
mouseup: (event) => {
const dx = event.pageX - context.xo;
const dy = event.pageY - context.yo;
off(window.document.body, handlers);
}
};
//on(window.document.body, handlers);
return { x: 40, y: 40, dragging: { context, handlers } };
}
},
H.div(
{
xmlns: "http://www.w3.org/1999/xhtml",
class: "handler",
style: {
cursor: "move",
border: "1px solid red",
background: "#FF0000A0"
}
},
H.p("Lorem ipsum"),
H.button("Hello")
)
)
);
});

const GraphCanvas = component(({ children, xpos, width, dragging }) => {
return H.svg(
{ width: "100%", height: "400px" },
H.rect({ fill: "#F0F0F0", width: "100%", height: "100%" }),
// Some props are unmapped
// TODO: I don't quite understand what happens with {x:100,y:100}, these should
// be part fo the state
GraphNode({ x: xpos, y: 40, width: 110, height: 150 })
/* NodeHandler({
x: $([x, width], ([x, width]) => (x || 0) + (width || 0)),
y: y
})*/
);
});
// We render the TodoList component with a default state.
return render(GraphCanvas, { xpos: 100 });
}
Insert cell
({ listItemBg:"#FFFFFF",
listItemHoverBg:"#EFF7FB",
listItemTxt:"#080F19",
listItemDisabledTxt: "#959BAB",
listItemSelectedBg:"#0A7CC3",
listItemSelectedTxt:"#FFFFFF",
listItemSelectedHoverBg:"#0A7CC3",
listItemSelectedHoverTxt:"#FFFFFF",
listItemLeftClickableSelected:"#0A7CC3",})

Insert cell
({
// These are the default "states" for things
normal:{bg:"#FFFFFF",txt:"#080F19"},
selected:{bg:"#0A7CC3",txt:"#FFFFFF"},
disabled:{txt:"#959BAB"},
list: {
item: {
// These are the overrides
normal:{bg:"#FFFFFF",txt:"#080F19"},
selected:{bg:"#0A7CC3",txt:"#FFFFFF"},
disabled:{txt:"#959BAB"},
}
}
})
// So that
// ListItem.selected would look for {selected} {ListeItem} and merge both
Insert cell
debug = (value, message) =>
new DebugEffector(
value,
(_) => console.log("PRE", message, _),
(_) => console.log("POST", message, _)
)
Insert cell
Insert cell
Insert cell
Insert cell
import { on, off } from "@sebastien/interaction"
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