Skip to content

Commit 834e5ee

Browse files
committed
fix #43; clear on fulfilled if no needed
1 parent 73a2f57 commit 834e5ee

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/runtime/define.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function define(main: Module, state: DefineState, definition: Definition,
3535
const variables = state.variables;
3636
const v = main.variable(observer(state, definition), {shadow: {}});
3737
const vid = output ?? (outputs.length ? `cell ${id}` : null);
38+
state.autoclear = true;
3839
if (inputs.includes("display") || inputs.includes("view")) {
3940
let displayVersion = -1; // the variable._version of currently-displayed values
4041
const vd = new (v.constructor as typeof Variable)(2, v._module);

src/runtime/display.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {mapAssets} from "./stdlib/assets.js";
55
export type DisplayState = {
66
/** the HTML element in which to render this cell’s display */
77
root: HTMLDivElement;
8+
/** whether to clear on fulfilled */
9+
autoclear?: boolean;
810
/** for inspected values, any expanded paths; see getExpanded */
911
expanded: (number[][] | undefined)[];
1012
};
@@ -42,6 +44,7 @@ function isDisplayable(value: unknown, root: HTMLDivElement): value is Node {
4244
}
4345

4446
export function clear(state: DisplayState): void {
47+
state.autoclear = false;
4548
state.expanded = Array.from(state.root.childNodes, getExpanded);
4649
while (state.root.lastChild) state.root.lastChild.remove();
4750
}
@@ -58,9 +61,11 @@ export function observe(state: DisplayState, {autodisplay, assets}: Definition)
5861
},
5962
fulfilled(value: unknown) {
6063
if (autodisplay) {
61-
clear(state);
6264
if (assets && value instanceof Element) mapAssets(value, assets);
65+
clear(state);
6366
display(state, value);
67+
} else if (state.autoclear) {
68+
clear(state);
6469
}
6570
},
6671
rejected(error: unknown) {

0 commit comments

Comments
 (0)