effect-atom-svelte-devtools 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ /** The graph frame-graph.svelte draws: its nodes and the edges between them. */
2
+ export type Kind = "effect" | "atom" | "component" | "junction" | "gone";
3
+ /** Which side of a node its label sits: north-east, south-east, and so on. */
4
+ type Side = "ne" | "se" | "nw" | "sw";
5
+ export interface GraphNode {
6
+ readonly x: number;
7
+ readonly y: number;
8
+ readonly kind: Kind;
9
+ readonly label?: string | undefined;
10
+ readonly note?: string | undefined;
11
+ /** Which side of the node its label sits: north-east (the default), south-east, and so on. */
12
+ readonly side?: Side | undefined;
13
+ /** The step at which it appears, with the edge that reaches it. */
14
+ readonly step?: number | undefined;
15
+ /** Names the node, for a live graph to find it again (`data-node`) and pulse it. */
16
+ readonly id?: string | undefined;
17
+ }
18
+ export interface GraphEdge {
19
+ readonly points: readonly (readonly [x: number, y: number])[];
20
+ readonly lit?: boolean | undefined;
21
+ readonly dashed?: boolean | undefined;
22
+ readonly step?: number | undefined;
23
+ /** The node it leads to (`data-to`), so a live graph can light the edges into a node. */
24
+ readonly to?: string | undefined;
25
+ /** Keeps an edge's element across redraws of a live graph. */
26
+ readonly id?: string | undefined;
27
+ }
28
+ export {};
@@ -0,0 +1,2 @@
1
+ /** The graph frame-graph.svelte draws: its nodes and the edges between them. */
2
+ export {};
@@ -1,5 +1,5 @@
1
1
  export { default as AtomGraph } from "./atom-graph.svelte";
2
2
  export { default as FrameGraph } from "./frame-graph.svelte";
3
- export type { GraphEdge, GraphNode, Kind } from "./frame-graph.svelte";
3
+ export type { GraphEdge, GraphNode, Kind } from "./graph-types.ts";
4
4
  export { layoutGraph, toneOf } from "./layout.ts";
5
5
  export type { GraphAtom, GraphDot, GraphInput, GraphLayout, GraphLink, GraphReader, } from "./layout.ts";
@@ -1,4 +1,6 @@
1
- import type { GraphEdge, GraphNode } from "./frame-graph.svelte";
1
+ import type { GraphEdge, GraphNode } from "./graph-types.ts";
2
+ /** Still held but read by nothing in view, or just removed. */
3
+ type AtomStatus = "live" | "held" | "removed";
2
4
  /** An atom to draw. */
3
5
  export interface GraphAtom {
4
6
  /** Stable for the atom, and in the order it was first seen: the layout keeps that order. */
@@ -7,7 +9,7 @@ export interface GraphAtom {
7
9
  /** The line under its name: its result, or why it's still held. */
8
10
  readonly note?: string | undefined;
9
11
  /** Still held but read by nothing in view (`held`), or just removed (`removed`, drawn crossed). */
10
- readonly status?: "live" | "held" | "removed" | undefined;
12
+ readonly status?: AtomStatus | undefined;
11
13
  /** Read by something, when there are no component readers to say so (the devtools panel). */
12
14
  readonly read?: boolean | undefined;
13
15
  }
@@ -63,3 +65,4 @@ export declare const toneOf: (state: string | undefined, waiting?: boolean) => "
63
65
  * depend on it: x is a fraction of the width, y is in pixels). Undefined when there's nothing to draw.
64
66
  */
65
67
  export declare const layoutGraph: (input: GraphInput, width: number) => GraphLayout | undefined;
68
+ export {};
@@ -22,7 +22,7 @@ const componentColumn = 0.72;
22
22
  const keyOf = (args) => {
23
23
  try {
24
24
  const value = JSON.parse(args);
25
- if (value && typeof value === "object") {
25
+ if (typeof value === "object" && value !== null) {
26
26
  return Object.values(value).map(String).join(" · ");
27
27
  }
28
28
  return String(value);
@@ -83,7 +83,7 @@ const parentsOf = (links, atoms, canonical) => {
83
83
  if (from !== to &&
84
84
  atoms.has(from) &&
85
85
  atoms.has(to) &&
86
- !parents.get(to)?.includes(from)) {
86
+ parents.get(to)?.includes(from) !== true) {
87
87
  append(parents, to, from);
88
88
  }
89
89
  }
@@ -100,6 +100,9 @@ const depthsOf = (atoms, parents) => {
100
100
  seen.add(id);
101
101
  const from = (parents.get(id) ?? []).filter((parent) => !seen.has(parent));
102
102
  const value = from.length === 0 ? 0 : 1 + Math.max(...from.map((p) => depth(p, seen)));
103
+ // Only the atoms on the path here are skipped: another child's path may reach this atom's
104
+ // parents too, as in a diamond.
105
+ seen.delete(id);
103
106
  depths.set(id, value);
104
107
  return value;
105
108
  };
@@ -269,11 +272,12 @@ const positions = (shape, tracks, dotted) => {
269
272
  const groupNode = (id, group, x, y) => {
270
273
  const repeats = group.dots.filter((dot) => dot.repeat).length;
271
274
  const keys = `${group.keys} ${group.keys === 1 ? "key" : "keys"}`;
275
+ const repeated = repeats > 0 ? ` · ${repeats} repeat a key` : "";
272
276
  return {
273
277
  id: `g${id}`,
274
278
  kind: "junction",
275
279
  label: `${group.name}(…)`,
276
- note: `${group.dots.length} atoms for ${keys}${repeats > 0 ? ` · ${repeats} repeat a key` : ""}`,
280
+ note: `${group.dots.length} atoms for ${keys}${repeated}`,
277
281
  side: "ne",
278
282
  x,
279
283
  y,
@@ -282,7 +286,7 @@ const groupNode = (id, group, x, y) => {
282
286
  const componentNote = (component) => {
283
287
  const kinds = new Set([...component.uses.values()].flatMap((uses) => [...uses]));
284
288
  if (!kinds.has("write")) {
285
- return undefined;
289
+ return;
286
290
  }
287
291
  return kinds.size === 1 ? "writes" : "reads, writes";
288
292
  };
@@ -9,6 +9,12 @@ export type ValueState = {
9
9
  export declare const valueState: (value: unknown) => ValueState;
10
10
  /** A short description of the state: `Success, waiting`. */
11
11
  export declare const stateText: (state: ValueState) => string;
12
+ /**
13
+ * What a failure failed with, from its first reason: a typed error by its name (`CityNotFound`),
14
+ * or with its fields, each written by `write`, when given; a defect as `defect: TypeError`; an
15
+ * interruption as `interrupted`.
16
+ */
17
+ export declare const failureText: (cause: Cause.Cause<unknown>, write?: (field: unknown) => string) => string;
12
18
  /**
13
19
  * Turns a value into plain data to print: an `AsyncResult` as its tag and contents, a failure's
14
20
  * cause pretty-printed, Effect's data types through their own `toJSON`, maps and sets as entries,
@@ -17,11 +23,5 @@ export declare const stateText: (state: ValueState) => string;
17
23
  export declare const plain: (value: unknown, depth?: number, seen?: Set<object>) => unknown;
18
24
  /** The value written out in full, for its sheet. */
19
25
  export declare const detail: (value: unknown) => string;
20
- /**
21
- * What a failure failed with, from its first reason: a typed error by its name (`CityNotFound`),
22
- * or with its fields when `full`; a defect as `defect: TypeError`; an interruption as
23
- * `interrupted`.
24
- */
25
- export declare const failureText: (cause: Cause.Cause<unknown>, full?: boolean) => string;
26
26
  /** The value on one line, cut to `length` characters. */
27
27
  export declare const preview: (value: unknown, length?: number) => string;
@@ -11,10 +11,66 @@ export const stateText = (state) => {
11
11
  }
12
12
  return state.waiting ? `${state._tag}, waiting` : state._tag;
13
13
  };
14
- const hasToJSON = (value) => typeof value.toJSON === "function";
14
+ const hasToJSON = (value) => typeof value === "object" &&
15
+ value !== null &&
16
+ "toJSON" in value &&
17
+ typeof value.toJSON === "function";
15
18
  // How much of a value is written out: deeper or longer parts are cut short.
16
19
  const maxDepth = 5;
17
20
  const maxItems = 50;
21
+ // Values JSON has no words for, written out bare: `NaN`, `Infinity`, `undefined`.
22
+ const bare = (text) => `\u0000${text}\u0000`;
23
+ const json = (data, indent) => (typeof data === "string"
24
+ ? JSON.stringify(data)
25
+ : (JSON.stringify(data, undefined, indent) ?? String(data))).replaceAll(/"\\u0000(?<text>.*?)\\u0000"/gu, "$<text>");
26
+ /** An error's name: a tagged error's `_tag`, an `Error`'s `name`, or the value as a string. */
27
+ const errorName = (error) => {
28
+ if (typeof error === "object" && error !== null) {
29
+ if ("_tag" in error && typeof error._tag === "string") {
30
+ return error._tag;
31
+ }
32
+ if (error instanceof Error) {
33
+ return error.name;
34
+ }
35
+ }
36
+ return String(error);
37
+ };
38
+ /**
39
+ * An error with its fields, each written by `write`, as `CityNotFound { city: "Atlantis" }`, or
40
+ * its message if it has one.
41
+ */
42
+ const errorText = (error, write) => {
43
+ const name = errorName(error);
44
+ if (typeof error !== "object" || error === null) {
45
+ return name;
46
+ }
47
+ if ("message" in error &&
48
+ typeof error.message === "string" &&
49
+ error.message !== "") {
50
+ return `${name}: ${error.message}`;
51
+ }
52
+ const fields = Object.entries(error).filter(([key]) => key !== "_tag");
53
+ const body = fields.map(([key, field]) => `${key}: ${write(field)}`);
54
+ return body.length > 0 ? `${name} { ${body.join(", ")} }` : name;
55
+ };
56
+ /**
57
+ * What a failure failed with, from its first reason: a typed error by its name (`CityNotFound`),
58
+ * or with its fields, each written by `write`, when given; a defect as `defect: TypeError`; an
59
+ * interruption as `interrupted`.
60
+ */
61
+ export const failureText = (cause, write) => {
62
+ const [reason] = cause.reasons;
63
+ if (reason === undefined) {
64
+ return "empty cause";
65
+ }
66
+ if (Cause.isFailReason(reason)) {
67
+ return write ? errorText(reason.error, write) : errorName(reason.error);
68
+ }
69
+ if (Cause.isDieReason(reason)) {
70
+ return `defect: ${write ? errorText(reason.defect, write) : errorName(reason.defect)}`;
71
+ }
72
+ return "interrupted";
73
+ };
18
74
  const plainResult = (result, inner) => {
19
75
  switch (result._tag) {
20
76
  case "Initial": {
@@ -27,16 +83,31 @@ const plainResult = (result, inner) => {
27
83
  waiting: result.waiting,
28
84
  };
29
85
  }
30
- default: {
86
+ case "Failure": {
87
+ // What it failed with, fields and all, as the graph's note promises; then the whole cause.
88
+ // oxlint-disable-next-line eslint/sort-keys -- what it failed with reads before the whole cause
31
89
  return {
32
90
  _tag: "Failure",
91
+ error: failureText(result.cause, (field) => json(inner(field))),
33
92
  cause: Cause.pretty(result.cause),
34
93
  waiting: result.waiting,
35
94
  };
36
95
  }
37
96
  }
38
97
  };
39
- const plainObject = (value, inner) => {
98
+ /** The first `maxItems` items, and how many more there are. */
99
+ const listed = (items, inner) => {
100
+ const shown = items.slice(0, maxItems).map(inner);
101
+ return items.length > maxItems
102
+ ? [...shown, `… ${items.length - maxItems} more`]
103
+ : shown;
104
+ };
105
+ /** An object cut to `maxItems` entries, saying how many more there are. */
106
+ const withMore = (object, count) => count > maxItems ? { ...object, "…": `${count - maxItems} more` } : object;
107
+ const isPrimitive = (value) => value === null || (typeof value !== "object" && typeof value !== "function");
108
+ const plainObject = (
109
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- any value an atom holds that isn't a primitive: there is no narrower type
110
+ value, inner) => {
40
111
  if (AsyncResult.isAsyncResult(value)) {
41
112
  return plainResult(value, inner);
42
113
  }
@@ -44,31 +115,37 @@ const plainObject = (value, inner) => {
44
115
  return value.toISOString();
45
116
  }
46
117
  if (value instanceof Error) {
47
- return `${value.name}: ${value.message}`;
118
+ // A tagged error's fields, as `CityNotFound { city: "Atlantis" }`.
119
+ return errorText(value, (field) => json(inner(field)));
48
120
  }
49
121
  if (value instanceof Map) {
50
- return Object.fromEntries([...value]
51
- .slice(0, maxItems)
52
- .map(([key, entry]) => [String(key), inner(entry)]));
122
+ const map = value;
123
+ const entries = [...map];
124
+ // Primitive keys that stay distinct as strings make an object; any other keys would collide
125
+ // or lose themselves as strings, so those maps are written as `[key, value]` pairs.
126
+ const keys = entries.map(([key]) => key);
127
+ if (keys.every((key) => isPrimitive(key)) &&
128
+ new Set(keys.map(String)).size === keys.length) {
129
+ return withMore(Object.fromEntries(entries
130
+ .slice(0, maxItems)
131
+ .map(([key, entry]) => [String(key), inner(entry)])), entries.length);
132
+ }
133
+ return listed(entries, ([key, entry]) => [inner(key), inner(entry)]);
53
134
  }
54
135
  if (value instanceof Set) {
55
- return [...value].slice(0, maxItems).map(inner);
136
+ return listed([...value], inner);
56
137
  }
57
138
  if (Array.isArray(value)) {
58
- const items = value.slice(0, maxItems).map(inner);
59
- return value.length > maxItems
60
- ? [...items, `… ${value.length - maxItems} more`]
61
- : items;
139
+ return listed(value, inner);
62
140
  }
63
141
  if (hasToJSON(value)) {
64
- const json = value.toJSON();
65
- if (json !== value) {
66
- return inner(json);
142
+ const data = value.toJSON();
143
+ if (data !== value) {
144
+ return inner(data);
67
145
  }
68
146
  }
69
- return Object.fromEntries(Object.entries(value)
70
- .slice(0, maxItems)
71
- .map(([key, entry]) => [key, inner(entry)]));
147
+ const entries = Object.entries(value);
148
+ return withMore(Object.fromEntries(entries.slice(0, maxItems).map(([key, entry]) => [key, inner(entry)])), entries.length);
72
149
  };
73
150
  /**
74
151
  * Turns a value into plain data to print: an `AsyncResult` as its tag and contents, a failure's
@@ -86,12 +163,19 @@ export const plain = (value, depth = 0, seen = new Set()) => {
86
163
  case "symbol": {
87
164
  return value.toString();
88
165
  }
89
- case "object": {
90
- break;
166
+ case "number": {
167
+ return Number.isFinite(value) ? value : bare(String(value));
168
+ }
169
+ case "undefined": {
170
+ return depth === 0 ? value : bare("undefined");
91
171
  }
92
- default: {
172
+ case "boolean":
173
+ case "string": {
93
174
  return value;
94
175
  }
176
+ case "object": {
177
+ break;
178
+ }
95
179
  }
96
180
  if (value === null) {
97
181
  return value;
@@ -113,56 +197,8 @@ export const plain = (value, depth = 0, seen = new Set()) => {
113
197
  seen.delete(value);
114
198
  }
115
199
  };
116
- const json = (data, indent) => typeof data === "string"
117
- ? JSON.stringify(data)
118
- : (JSON.stringify(data, undefined, indent) ?? String(data));
119
200
  /** The value written out in full, for its sheet. */
120
201
  export const detail = (value) => json(plain(value), 2);
121
- /** An error's name: a tagged error's `_tag`, an `Error`'s `name`, or the value as a string. */
122
- const errorName = (error) => {
123
- if (typeof error === "object" && error !== null) {
124
- if ("_tag" in error && typeof error._tag === "string") {
125
- return error._tag;
126
- }
127
- if (error instanceof Error) {
128
- return error.name;
129
- }
130
- }
131
- return String(error);
132
- };
133
- /** An error with its fields, as `CityNotFound { city: "Atlantis" }`, or its message if it has one. */
134
- const errorText = (error) => {
135
- const name = errorName(error);
136
- if (typeof error !== "object" || error === null) {
137
- return name;
138
- }
139
- if ("message" in error &&
140
- typeof error.message === "string" &&
141
- error.message !== "") {
142
- return `${name}: ${error.message}`;
143
- }
144
- const fields = Object.entries(error).filter(([key]) => key !== "_tag");
145
- const body = fields.map(([key, field]) => `${key}: ${json(plain(field))}`);
146
- return body.length > 0 ? `${name} { ${body.join(", ")} }` : name;
147
- };
148
- /**
149
- * What a failure failed with, from its first reason: a typed error by its name (`CityNotFound`),
150
- * or with its fields when `full`; a defect as `defect: TypeError`; an interruption as
151
- * `interrupted`.
152
- */
153
- export const failureText = (cause, full = false) => {
154
- const [reason] = cause.reasons;
155
- if (reason === undefined) {
156
- return "empty cause";
157
- }
158
- if (Cause.isFailReason(reason)) {
159
- return full ? errorText(reason.error) : errorName(reason.error);
160
- }
161
- if (Cause.isDieReason(reason)) {
162
- return `defect: ${full ? errorText(reason.defect) : errorName(reason.defect)}`;
163
- }
164
- return "interrupted";
165
- };
166
202
  /** An `AsyncResult` on one line: its value, through `inner`, or what it failed with. */
167
203
  const resultText = (result, inner) => {
168
204
  let text = "Initial";
@@ -170,7 +206,7 @@ const resultText = (result, inner) => {
170
206
  text = inner(result.value);
171
207
  }
172
208
  else if (result._tag === "Failure") {
173
- text = failureText(result.cause, true);
209
+ text = failureText(result.cause, (field) => json(plain(field)));
174
210
  }
175
211
  return result.waiting ? `${text}, waiting` : text;
176
212
  };
@@ -4,10 +4,10 @@
4
4
  effect is interrupted or an atom removed. Clicking an atom opens its sheet.
5
5
  -->
6
6
  <script lang="ts">
7
- import { AtomGraph, toneOf } from "../graph/index.js";
8
- import type { GraphAtom, GraphInput } from "../graph/index.js";
9
7
  import { AsyncResult } from "effect/reactivity";
10
8
 
9
+ import { AtomGraph, toneOf } from "../graph/index.js";
10
+ import type { GraphAtom, GraphInput } from "../graph/index.js";
11
11
  import { failureText, preview, stateText } from "./format.js";
12
12
  import type { AtomView } from "./model.svelte.js";
13
13
  import { lingerFor } from "./model.svelte.js";
@@ -23,10 +23,11 @@
23
23
 
24
24
  let graph = $state<AtomGraph>();
25
25
 
26
+ const lingering = (view: AtomView) =>
27
+ view.removedAt !== undefined &&
28
+ performance.now() - view.removedAt < lingerFor;
26
29
  const shown = (view: AtomView) =>
27
- (showPlumbing || !view.plumbing) &&
28
- (view.live ||
29
- (view.removedAt !== undefined && performance.now() - view.removedAt < lingerFor));
30
+ (showPlumbing || !view.plumbing) && (view.live || lingering(view));
30
31
 
31
32
  /** Why the registry holds an atom nothing reads. */
32
33
  const heldBecause = (view: AtomView) => {
@@ -52,10 +53,16 @@
52
53
  const state = stateText(view.state);
53
54
  let value = view.hasValue ? preview(view.value, 26) : "";
54
55
  // A failure shows what it failed with, by name: its fields are on its sheet.
55
- if (AsyncResult.isAsyncResult(view.value) && AsyncResult.isFailure(view.value)) {
56
+ if (
57
+ AsyncResult.isAsyncResult(view.value) &&
58
+ AsyncResult.isFailure(view.value)
59
+ ) {
56
60
  value = failureText(view.value.cause);
57
61
  }
58
- const withValue = state === "" || view.state._tag === "Success" || view.state._tag === "Failure";
62
+ const withValue =
63
+ state === "" ||
64
+ view.state._tag === "Success" ||
65
+ view.state._tag === "Failure";
59
66
  const parts = [state, withValue ? value : ""];
60
67
  if (view.readers === 0 && view.children.length === 0) {
61
68
  parts.push(heldBecause(view));
@@ -83,16 +90,16 @@
83
90
  return found;
84
91
  };
85
92
  return {
86
- atoms: visible.map(
87
- (view): GraphAtom => ({
88
- id: view.id,
89
- label: view.name,
90
- note: note(view),
91
- read: view.readers > 0,
92
- status: statusOf(view),
93
- })
93
+ atoms: visible.map((view): GraphAtom => ({
94
+ id: view.id,
95
+ label: view.name,
96
+ note: note(view),
97
+ read: view.readers > 0,
98
+ status: statusOf(view),
99
+ })),
100
+ links: visible.flatMap((view) =>
101
+ [...parentsOf(view)].map((from) => ({ from, to: view.id }))
94
102
  ),
95
- links: visible.flatMap((view) => [...parentsOf(view)].map((from) => ({ from, to: view.id }))),
96
103
  };
97
104
  });
98
105
 
@@ -41,14 +41,11 @@ const setLabel = (atom, text, at, kind) => {
41
41
  if (!free && !(previous !== undefined && replaces[kind].includes(previous))) {
42
42
  return;
43
43
  }
44
- try {
45
- // The second element is a stack frame, as Effect's own labels hold.
46
- atom.label = [text, `at ${text} (${at})`];
44
+ // The second element is a stack frame, as Effect's own labels hold. A frozen atom keeps the
45
+ // label it has.
46
+ if (Reflect.set(atom, "label", [text, `at ${text} (${at})`])) {
47
47
  kinds.set(atom, kind);
48
48
  }
49
- catch {
50
- // A frozen atom keeps the label it has.
51
- }
52
49
  };
53
50
  /** A family member's argument, short enough for a label. */
54
51
  const formatArg = (arg) => {
@@ -91,9 +88,26 @@ export const keepAcrossReloads = (atom, key, source, inRegistries = registries)
91
88
  }
92
89
  const release = registry.mount(atom);
93
90
  registry.set(atom, node.value());
91
+ // oxlint-disable-next-line effecttsgo/global-timers -- runs in the app's page, outside any Effect program
94
92
  setTimeout(release, holdFor);
95
93
  }
96
94
  };
95
+ // A function the plugin wrapped can take anything and return anything: `label` and `call` only
96
+ // pass its arguments through and look at what it returns.
97
+ const isFunction = (value) => typeof value === "function";
98
+ const isObjectLike = (value) => typeof value === "object" && value !== null;
99
+ // The key a form definition from `Form.make` carries (effect-atom-svelte's `Form.TypeId`).
100
+ const formTypeId = "~effect-atom-svelte/Form";
101
+ /** A form definition that `Form.make` was given no name for. */
102
+ const isUnnamedForm = (value) => {
103
+ if (!isObjectLike(value) || !(formTypeId in value && "definition" in value)) {
104
+ return false;
105
+ }
106
+ const { definition } = value;
107
+ return (isObjectLike(definition) &&
108
+ "name" in definition &&
109
+ definition.name === undefined);
110
+ };
97
111
  /**
98
112
  * Labels `value` with `text` and the place it was declared, `at` (`/src/lib/todos.ts:12:14`), if
99
113
  * it is an atom, and returns it. For an `Atom.family`, returns a family that labels each member
@@ -101,20 +115,27 @@ export const keepAcrossReloads = (atom, key, source, inRegistries = registries)
101
115
  */
102
116
  export const label = (value, text, at, options = {}) => {
103
117
  if (Atom.isAtom(value)) {
104
- setLabel(value, text, at, options.local ? "local" : "declaration");
118
+ setLabel(value, text, at, options.local === true ? "local" : "declaration");
105
119
  if (options.keep !== undefined) {
106
120
  keepAcrossReloads(value, `${at.replace(/:\d+:\d+$/u, "")}#${text}`, options.keep);
107
121
  }
108
122
  }
109
- else if (options.family && typeof value === "function") {
110
- const members = value;
111
- return ((arg) => {
112
- const member = members(arg);
123
+ else if (isUnnamedForm(value)) {
124
+ // A form from effect-atom-svelte's Form.make: its instances label their atoms with its name.
125
+ value.definition.name = text;
126
+ }
127
+ else if (options.family === true && isFunction(value)) {
128
+ const labelled = (arg) => {
129
+ const member = value(arg);
113
130
  if (Atom.isAtom(member)) {
114
131
  setLabel(member, `${text}(${formatArg(arg)})`, at, "family");
115
132
  }
116
133
  return member;
117
- });
134
+ };
135
+ // SAFETY: `value` is an `Atom.family`, a function of one argument; `labelled` takes the same
136
+ // argument and returns the same member, so it stands in for it.
137
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- a wrapper can't be typed as the generic it wraps
138
+ return labelled;
118
139
  }
119
140
  return value;
120
141
  };
@@ -124,16 +145,18 @@ export const label = (value, text, at, options = {}) => {
124
145
  * two atoms made for equal keys get the same name; an atom returned again keeps the name it has.
125
146
  */
126
147
  export const call = (f, name, at) => {
127
- if (typeof f !== "function") {
148
+ if (!isFunction(f)) {
128
149
  // Calling it fails as the code would have without the plugin.
129
150
  return f;
130
151
  }
131
- const factory = f;
132
- return ((...args) => {
133
- const result = factory(...args);
152
+ const labelled = (...args) => {
153
+ const result = f(...args);
134
154
  if (Atom.isAtom(result)) {
135
155
  setLabel(result, `${name}(${args.map(formatArg).join(", ")})`, at, "call");
136
156
  }
137
157
  return result;
138
- });
158
+ };
159
+ // SAFETY: `f` is a function; `labelled` takes the same arguments and returns what `f` does.
160
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- a wrapper can't be typed as the generic it wraps
161
+ return labelled;
139
162
  };
@@ -25,7 +25,7 @@ const causeText = (cause, nameOf) => {
25
25
  case "ParentChanged": {
26
26
  return `${cause.parents.map(nameOf).join(", ")} changed`;
27
27
  }
28
- default: {
28
+ case "Invalidated": {
29
29
  return "invalidated";
30
30
  }
31
31
  }
@@ -70,7 +70,9 @@ export class Model {
70
70
  entry.hasValue = true;
71
71
  }
72
72
  }
73
- const unsubscribe = this.#inspector.subscribe((event) => this.#receive(event));
73
+ const unsubscribe = this.#inspector.subscribe((event) => {
74
+ this.#receive(event);
75
+ });
74
76
  this.#schedule();
75
77
  return () => {
76
78
  unsubscribe();
@@ -91,6 +93,8 @@ export class Model {
91
93
  }
92
94
  clearTimeline() {
93
95
  this.#log = [];
96
+ // Paused too: clearing is asked of the timeline on screen.
97
+ this.timeline = [];
94
98
  this.#schedule();
95
99
  }
96
100
  #entry(atom) {
@@ -168,13 +172,17 @@ export class Model {
168
172
  detail = `${event.finalizers} ${event.finalizers === 1 ? "finalizer" : "finalizers"} ran`;
169
173
  break;
170
174
  }
171
- default: {
175
+ case "NodeRemoved": {
172
176
  entry.node = undefined;
173
177
  entry.removedAt = event.time;
174
178
  detail = "removed";
175
179
  // Again once it has lingered, to take it off the graph.
176
- setTimeout(() => this.#schedule(), lingerFor + 50);
180
+ // oxlint-disable-next-line effecttsgo/global-timers -- the panel's UI scheduling, outside any Effect program
181
+ setTimeout(() => {
182
+ this.#schedule();
183
+ }, lingerFor + 50);
177
184
  this.#prune();
185
+ break;
178
186
  }
179
187
  }
180
188
  this.#seq += 1;
@@ -210,6 +218,34 @@ export class Model {
210
218
  this.#publish();
211
219
  });
212
220
  }
221
+ #view(entry, plumbing, state) {
222
+ const { node } = entry;
223
+ return {
224
+ atom: entry.atom,
225
+ builds: entry.builds,
226
+ children: node === undefined
227
+ ? []
228
+ : [...node.children].map((child) => this.#entry(child.atom).id),
229
+ hasValue: entry.hasValue,
230
+ id: entry.id,
231
+ identity: entry.identity,
232
+ idleTTL: this.#inspector.idleTTL(entry.atom),
233
+ interruptedAt: entry.interruptedAt,
234
+ interruptions: entry.interruptions,
235
+ keepAlive: entry.atom.keepAlive,
236
+ live: node !== undefined,
237
+ name: this.#name(entry),
238
+ parents: node === undefined
239
+ ? []
240
+ : [...node.parents].map((parent) => this.#entry(parent.atom).id),
241
+ plumbing,
242
+ readers: node?.listeners.size ?? 0,
243
+ removedAt: entry.removedAt,
244
+ state,
245
+ updates: entry.updates,
246
+ value: entry.value,
247
+ };
248
+ }
213
249
  #publish() {
214
250
  const now = performance.now();
215
251
  const views = [];
@@ -240,31 +276,7 @@ export class Model {
240
276
  const stateKey = state._tag === "Value" ? "Value" : state._tag;
241
277
  states[stateKey] = (states[stateKey] ?? 0) + 1;
242
278
  }
243
- views.push({
244
- atom: entry.atom,
245
- builds: entry.builds,
246
- children: node === undefined
247
- ? []
248
- : [...node.children].map((child) => this.#entry(child.atom).id),
249
- hasValue: entry.hasValue,
250
- id: entry.id,
251
- identity: entry.identity,
252
- idleTTL: this.#inspector.idleTTL(entry.atom),
253
- interruptedAt: entry.interruptedAt,
254
- interruptions: entry.interruptions,
255
- keepAlive: entry.atom.keepAlive,
256
- live: node !== undefined,
257
- name: this.#name(entry),
258
- parents: node === undefined
259
- ? []
260
- : [...node.parents].map((parent) => this.#entry(parent.atom).id),
261
- plumbing: isPlumbing,
262
- readers: node?.listeners.size ?? 0,
263
- removedAt: entry.removedAt,
264
- state,
265
- updates: entry.updates,
266
- value: entry.value,
267
- });
279
+ views.push(this.#view(entry, isPlumbing, state));
268
280
  }
269
281
  this.atoms = views;
270
282
  this.totals = {