-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
This has been an idea in the back of my head for a while, but this issue made me put it into better words.
Basically, with .moduleToESModule() and .module(), it would be nice to be able to specify a list of cells, and the compiled output only defines the cells needed to execute up to the specified cells. For example, if the original source is like:
a = 1;
b = 2;
c = a + b;
x = 2;
y = 4;
z = x - y;
import {d3, chart} with {c as height} from "@d3/bar-chart";
Then we could specify the following to get different outputs.
c, z:
export default function define(runtime, observer) {
const main = runtime.module();
main.variable(observer("a")).define("a", function(){return(
1
)});
main.variable(observer("b")).define("b", function(){return(
2
)});
main.variable(observer("c")).define("c", ["a","b"], function(a,b){return(
a + b
)});
main.variable(observer("x")).define("x", function(){return(
2
)});
main.variable(observer("y")).define("y", function(){return(
4
)});
main.variable(observer("z")).define("z", ["x","y"], function(x,y){return(
x - y
)});
return main;
}
a, x
export default function define(runtime, observer) {
const main = runtime.module();
main.variable(observer("a")).define("a", function(){return(
1
)});
main.variable(observer("x")).define("x", function(){return(
2
)});
return main;
}
chart
import define1 from "https://api.observablehq.com/@d3/bar-chart.js?v=3";
export default function define(runtime, observer) {
const main = runtime.module();
main.variable(observer("a")).define("a", function(){return(
1
)});
main.variable(observer("b")).define("b", function(){return(
2
)});
main.variable(observer("c")).define("c", ["a","b"], function(a,b){return(
a + b
)});
const child1 = runtime.module(define1).derive([{"name":"c","alias":"height"}], main);
main.import("d3", "d3", child1);
main.import("chart", "chart", child1);
return main;
}
To do it, we would probably need to create the cell's DAG and determine which cells to include/exclude. Also to remove unnecessary import statements (while being careful with edge import with cases), and maybe unnecessary FileAttachments too, but that may be harder...
a10k and JobLeonard
Metadata
Metadata
Assignees
Labels
No labels