@lukekaalim/act-insight 1.0.0 → 2.0.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.
Files changed (123) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/InsightApp.module.css +36 -0
  3. package/InsightApp2.ts +82 -0
  4. package/TreeViewer.module.css +3 -8
  5. package/TreeViewer.ts +16 -12
  6. package/Virtual.ts +29 -11
  7. package/assets/icons/ancestor_column.png +0 -0
  8. package/assets/icons/ancestor_column.svg +26 -0
  9. package/assets/icons/ancestor_skip_row_column.png +0 -0
  10. package/assets/icons/ancestor_skip_row_column.svg +52 -0
  11. package/assets/icons/breakpoint.png +0 -0
  12. package/assets/icons/breakpoint.svg +33 -0
  13. package/assets/icons/breakpoint_arrow.png +0 -0
  14. package/assets/icons/breakpoint_arrow.svg +22 -0
  15. package/assets/icons/breakpoint_arrow_paused.png +0 -0
  16. package/assets/icons/breakpoint_arrow_paused.svg +38 -0
  17. package/assets/icons/breakpoint_panel.png +0 -0
  18. package/assets/icons/breakpoint_panel.svg +121 -0
  19. package/assets/icons/breakpoint_unset.png +0 -0
  20. package/assets/icons/breakpoint_unset.svg +26 -0
  21. package/assets/icons/bug.png +0 -0
  22. package/assets/icons/bug.svg +65 -0
  23. package/assets/icons/children.png +0 -0
  24. package/assets/icons/children.svg +38 -0
  25. package/assets/icons/collapse.png +0 -0
  26. package/assets/icons/collapse.svg +38 -0
  27. package/assets/icons/commit.png +0 -0
  28. package/assets/icons/commit.svg +30 -0
  29. package/assets/icons/commit_tree.png +0 -0
  30. package/assets/icons/commit_tree.svg +44 -0
  31. package/assets/icons/effect.png +0 -0
  32. package/assets/icons/effect.svg +28 -0
  33. package/assets/icons/expand.png +0 -0
  34. package/assets/icons/expand.svg +47 -0
  35. package/assets/icons/eye.png +0 -0
  36. package/assets/icons/eye.svg +36 -0
  37. package/assets/icons/eye_closed.png +0 -0
  38. package/assets/icons/eye_closed.svg +32 -0
  39. package/assets/icons/filter.png +0 -0
  40. package/assets/icons/filter.svg +22 -0
  41. package/assets/icons/graph.png +0 -0
  42. package/assets/icons/graph.svg +129 -0
  43. package/assets/icons/history_list.png +0 -0
  44. package/assets/icons/history_list.svg +60 -0
  45. package/assets/icons/hook.png +0 -0
  46. package/assets/icons/hook.svg +22 -0
  47. package/assets/icons/index.ts +76 -0
  48. package/assets/icons/inspector_panel.png +0 -0
  49. package/assets/icons/inspector_panel.svg +135 -0
  50. package/assets/icons/magnifying_glass.png +0 -0
  51. package/assets/icons/magnifying_glass.svg +39 -0
  52. package/assets/icons/pause.png +0 -0
  53. package/assets/icons/pause.svg +34 -0
  54. package/assets/icons/play.png +0 -0
  55. package/assets/icons/play.svg +23 -0
  56. package/assets/icons/reload.png +0 -0
  57. package/assets/icons/reload.svg +39 -0
  58. package/assets/icons/selection.png +0 -0
  59. package/assets/icons/selection.svg +22 -0
  60. package/assets/icons/side_effects.png +0 -0
  61. package/assets/icons/side_effects.svg +48 -0
  62. package/assets/icons/skip.png +0 -0
  63. package/assets/icons/skip.svg +22 -0
  64. package/assets/icons/source.svg +1366 -0
  65. package/assets/icons/step.png +0 -0
  66. package/assets/icons/step.svg +51 -0
  67. package/assets/icons/step_over_children.png +0 -0
  68. package/assets/icons/step_over_children.svg +57 -0
  69. package/assets/icons/thread.png +0 -0
  70. package/assets/icons/thread.svg +32 -0
  71. package/assets/icons/tree_column.png +0 -0
  72. package/assets/icons/tree_column.svg +26 -0
  73. package/assets/icons/tree_end.png +0 -0
  74. package/assets/icons/tree_end.svg +35 -0
  75. package/assets/icons/tree_junction.png +0 -0
  76. package/assets/icons/tree_junction.svg +35 -0
  77. package/assets/icons/vertical_grab_handle.png +0 -0
  78. package/assets/icons/vertical_grab_handle.svg +36 -0
  79. package/components/BreakpointPanel.ts +110 -0
  80. package/components/BreakpointToggle.ts +14 -0
  81. package/components/Button.ts +53 -0
  82. package/components/Checkbox.ts +17 -0
  83. package/components/CommitInspector.ts +161 -0
  84. package/components/CommitTree.ts +295 -0
  85. package/components/ControlBar.ts +60 -0
  86. package/components/EffectTable.ts +125 -0
  87. package/components/FiltersPanel.ts +45 -0
  88. package/components/HistoryList.ts +0 -0
  89. package/components/InspectorPanel.ts +54 -0
  90. package/components/PlaybackBar.ts +42 -0
  91. package/components/ThreadInspector.ts +26 -0
  92. package/components/index.module.css +414 -0
  93. package/lib/controller.ts +222 -0
  94. package/lib/list.ts +82 -0
  95. package/lib/selection.ts +32 -0
  96. package/package.json +4 -4
  97. package/public/icons/icons.svg +520 -0
  98. package/public/icons/icons__breakpoint.png +0 -0
  99. package/public/icons/icons__breakpoint.svg +30 -0
  100. package/public/icons/icons__breakpoint_panel.png +0 -0
  101. package/public/icons/icons__breakpoint_panel.svg +121 -0
  102. package/public/icons/icons__children.png +0 -0
  103. package/public/icons/icons__children.svg +38 -0
  104. package/public/icons/icons__eye.png +0 -0
  105. package/public/icons/icons__eye.svg +36 -0
  106. package/public/icons/icons__inspector_panel.png +0 -0
  107. package/public/icons/icons__inspector_panel.svg +131 -0
  108. package/public/icons/icons__magnifying_glass.png +0 -0
  109. package/public/icons/icons__magnifying_glass.svg +39 -0
  110. package/public/icons/icons__pause.png +0 -0
  111. package/public/icons/icons__pause.svg +34 -0
  112. package/public/icons/icons__play.png +0 -0
  113. package/public/icons/icons__play.svg +23 -0
  114. package/public/icons/icons__skip.png +0 -0
  115. package/public/icons/icons__skip.svg +22 -0
  116. package/public/icons/icons__step.png +0 -0
  117. package/public/icons/icons__step.svg +51 -0
  118. package/utils.ts +78 -11
  119. package/InsightApp.ts +0 -365
  120. package/MenuBar.module.css +0 -18
  121. package/MenuBar.ts +0 -39
  122. package/ScheduleControls.ts +0 -61
  123. package/lookup.ts +0 -185
package/InsightApp.ts DELETED
@@ -1,365 +0,0 @@
1
- import { Component, h, useEffect, useMemo, useRef, useState } from '@lukekaalim/act';
2
- import { CommitDetailsReport, CommitReport, DeltaReport, ReconcilerDebugController, ReconcilerDebugEventBus, ThreadReport, updateTreeReport, ValueReport, WorkTaskReport } from '@lukekaalim/act-debug';
3
- import { CommitID } from '@lukekaalim/act-recon';
4
- import { CommitPreview, TreeViewer } from './TreeViewer';
5
- import { ScheduleControls } from './ScheduleControls';
6
- import { CommitLookupCache, ThreadLookupCache } from './lookup';
7
- import { Virtual1D } from './Virtual';
8
- import { CommitAttributeTag } from './AttributeTag';
9
-
10
- export type InsightAppProps = {
11
- controller: ReconcilerDebugController,
12
- bus: ReconcilerDebugEventBus,
13
-
14
- document: Document,
15
- };
16
-
17
- export type InsightAppState = {
18
- breakOnAfterUpdate: boolean,
19
- breakOnBeforeUpdate: boolean,
20
-
21
- commitBreakpoints: Set<CommitID>,
22
-
23
- paused: boolean,
24
- }
25
-
26
- export const InsightApp: Component<InsightAppProps> = ({ controller, bus, document = window.document }) => {
27
- const [c, setRenderCounter] = useState(0);
28
-
29
- const [insightState, setInsightState] = useState<InsightAppState>({
30
- commitBreakpoints: new Set(),
31
- breakOnAfterUpdate: false,
32
- breakOnBeforeUpdate: false,
33
- paused: false,
34
- });
35
-
36
- const commitCache = useRef(() => new CommitLookupCache()).current;
37
- const deltaCache = useRef(() => new ThreadLookupCache(commitCache)).current;
38
-
39
- useMemo(() => {
40
- commitCache.setTree(controller.getTree())
41
- deltaCache.reset();
42
- }, [])
43
-
44
- useEffect(() => {
45
- console.log('[Insight] Populate Cache')
46
-
47
- bus.onThreadDone = (thread, delta) => {
48
- console.log('[Insight] ThreadDone')
49
-
50
- deltaCache.ingestDelta(delta);
51
- deltaCache.ingestThread(thread);
52
- deltaCache.prevTask = null;
53
- setRenderCounter(c => c + 1);
54
-
55
- for (const subscriber of cacheSubscribers) {
56
- subscriber();
57
- }
58
- }
59
- bus.thread.onQueue = (reason) => {
60
- console.log('[Insight] OnQueue')
61
- const thread = controller.getThread();
62
-
63
- if (thread.reasons.length === 1) {
64
- if (insightState.breakOnBeforeUpdate)
65
- controller.scheduler.intercept = true;
66
-
67
- if (deltaCache.report)
68
- commitCache.ingest(deltaCache.report);
69
-
70
- deltaCache.reset();
71
- deltaCache.ingestThread(thread);
72
- setRenderCounter(c => c + 1);
73
-
74
- for (const subscriber of cacheSubscribers) {
75
- subscriber();
76
- }
77
- }
78
- }
79
- bus.thread.onWork = (prevTask, nextTask, isDone) => {
80
-
81
- if (insightState.breakOnAfterUpdate && isDone) {
82
- controller.scheduler.intercept = true;
83
- }
84
- if (nextTask && insightState.commitBreakpoints.has(nextTask.id)) {
85
- controller.scheduler.intercept = true;
86
- }
87
-
88
- if (controller.scheduler.intercept) {
89
- const thread = controller.getThread();
90
- const delta = controller.getDelta();
91
-
92
- deltaCache.ingestDelta(delta);
93
- deltaCache.ingestThread(thread);
94
- setRenderCounter(c => c + 1);
95
-
96
- for (const subscriber of cacheSubscribers) {
97
- subscriber();
98
- }
99
-
100
- if (prevTask)
101
- deltaCache.prevTask = prevTask;
102
- }
103
- }
104
- }, [controller, bus, insightState]);
105
-
106
- const cacheSubscribers = useRef<Set<() => void>>(new Set()).current;
107
-
108
- const scrollToCommitIndex = useMemo(() => {
109
- return (index: number) => {
110
- if (!viewportRef.current)
111
- return;
112
- const viewPortRect = viewportRef.current.getBoundingClientRect();
113
- if (index) {
114
- viewportRef.current.scrollTo({
115
- top: (index * 33) - (viewPortRect.height / 2),
116
- behavior: 'smooth'
117
- })
118
- return;
119
- }
120
- }
121
- }, []);
122
-
123
- useEffect(() => {
124
- const { nextTask, prevTask } = deltaCache;
125
-
126
- const task = nextTask || prevTask;
127
- const index = task && commits.findIndex(c => (nextTask && c.id === nextTask.id) || (prevTask && prevTask.id === c.id));
128
-
129
- if (index && index !== -1) {
130
- scrollToCommitIndex(index);
131
- }
132
- }, [deltaCache.prevTask, deltaCache.nextTask, scrollToCommitIndex])
133
-
134
- const renderCommit = useMemo(() => (commitId: CommitID) => {
135
- return h(CommitComponent, { commitId })
136
- }, []);
137
-
138
- const CommitComponent = useMemo((): Component<{ commitId: CommitID }> => ({ commitId }) => {
139
- const [c, setRenderCounter] = useState(0);
140
-
141
- useEffect(() => {
142
- const subscription = () => {
143
- const commit = deltaCache.all.get(commitId);
144
- const originalCommit = commitCache.map.get(commitId);
145
-
146
- const inTaskList = deltaCache.allTasks.has(commitId);
147
-
148
- if (commit !== originalCommit || inTaskList || (deltaCache.prevTask && deltaCache.prevTask.id === commitId))
149
- setRenderCounter(c => c + 1);
150
- }
151
- cacheSubscribers.add(subscription);
152
- subscription();
153
-
154
- return () => {
155
- console.log(`[Commit] Cleaning up ${commitId}`)
156
- cacheSubscribers.delete(subscription);
157
- }
158
- }, [commitId])
159
-
160
- const commit = deltaCache.all.get(commitId) || null;
161
- if (!commit)
162
- return (console.warn(`[Commit] Commit ${commitId} not found in delta cache`), null);
163
-
164
- const color =
165
- (deltaCache.nextTask && deltaCache.nextTask.id === commit.id) ? '#e1d600ff'
166
- : deltaCache.targets.has(commit.id) ? '#db55e7ff'
167
- : deltaCache.allTasks.has(commit.id) ? '#ea931aff'
168
- : deltaCache.created.has(commit.id) ? (deltaCache.prevTask && deltaCache.prevTask.id === commit.id ? '#4bc847ff' : '#21a51cff')
169
- : deltaCache.removed.has(commit.id) ? '#f25252ff'
170
- : deltaCache.updated.has(commit.id) ? '#1ab9eaff'
171
- : deltaCache.visited.has(commit.id) ? '#6f6f97ff'
172
- : '#cacaca';
173
-
174
- if (!commit)
175
- return (console.log(`[Commit] ${commitId} not ready yet??`), null);
176
-
177
- return useMemo(() => h(CommitPreview, { commit, renderCommit, color, onClick: () => setSelectedCommitId(commit.id) }), [
178
- commit.version,
179
- color,
180
- ])
181
- }, [])
182
-
183
- const viewportRef = useRef<HTMLElement | null>(null);
184
-
185
- const [selectedCommitId, setSelectedCommitId] = useState<CommitID | null>(null)
186
- const [selectedCommitDetails, setSelectedCommitDetails] = useState<CommitDetailsReport | null>(null)
187
-
188
- useEffect(() => {
189
- if (!selectedCommitId)
190
- return;
191
-
192
- const details = controller.getDetails(selectedCommitId);
193
- setSelectedCommitDetails(details)
194
- }, [selectedCommitId])
195
-
196
- const roots = [...deltaCache.roots.keys()];
197
- const commits = deltaCache.getFlat();
198
-
199
- const CHUNK_SIZE = 8;
200
-
201
- return h('div', { style: { display: 'flex', 'flex-direction': 'column', position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 } }, [
202
- h('div', { style: { flex: 0, display: 'flex' } }, [
203
- h(ScheduleControls, {
204
- controller: controller.scheduler,
205
- bus: bus.scheduler,
206
- reconciler: controller,
207
-
208
- state: insightState,
209
- onStateChange: setInsightState,
210
- }),
211
- ]),
212
- h('div', { style: { flex: 1, overflow: 'hidden', background: '#c0d7ddff', display: 'flex' } }, [
213
- h('div', { style: { flex: 1 } },
214
- //h(TreeViewer, { roots, renderCommit }),
215
- h(Virtual1D, { viewportRef, windowRange: 5, chunkCount: commits.length / CHUNK_SIZE, chunkSize: (33 * CHUNK_SIZE), renderChunk(index) {
216
- if (index < 0)
217
- return null;
218
-
219
- return Array.from({ length: CHUNK_SIZE }).map((_, chunkIndex) => {
220
- const report = commits[(index * CHUNK_SIZE) + (chunkIndex)];
221
- if (!report)
222
- return null;
223
-
224
- const color = getCommitColor(deltaCache, report.id);
225
-
226
- const onClick = () => {
227
- setSelectedCommitId(report.id);
228
- };
229
- const attributes: [string, string][] = [
230
- insightState.commitBreakpoints.has(report.id) ? ['Breakpoint', 'Enabled'] as [string, string] : null
231
- ].filter(x => !!x)
232
-
233
- return h('div', { style: { 'margin-left': ((report.distance - 1) * 32) + 'px', height: '33px' } }, [
234
- h(CommitPreview, { color, commit: report, onClick, attributes })
235
- ])
236
- });
237
- }, })
238
- ),
239
- h('div', { style: { 'min-width': '300px', flex: 0, background: '#ffdeabff' } }, [
240
- deltaCache.thread && h('div', { }, [
241
- h('dl', {}, [
242
- h('dt', {}, 'Thread ID'),
243
- h('dd', {}, deltaCache.thread.id),
244
- h('dt', {}, 'Thread Done'),
245
- h('dd', {}, deltaCache.thread.done.toString()),
246
- h('dt', {}, 'Thread Passes'),
247
- h('dd', {}, deltaCache.thread.passes),
248
- h('dt', {}, 'Tasks (count)'),
249
- h('dd', {}, deltaCache.thread.pendingTasks.length),
250
- h('dt', {}, 'Visited (count)'),
251
- h('dd', {}, deltaCache.thread.visited.length),
252
- h('dt', {}, 'Created (count)'),
253
- h('dd', {}, deltaCache.created.size),
254
- h('dt', {}, 'Updated (count)'),
255
- h('dd', {}, deltaCache.updated.size),
256
- h('dt', {}, 'Removed (count)'),
257
- h('dd', {}, deltaCache.removed.size),
258
- h('dt', {}, 'MustRender '),
259
- h('dd', {}, deltaCache.thread.mustRender.map(commitId => {
260
- const commit = deltaCache.all.get(commitId);
261
- if (!commit)
262
- return null;
263
- const color = getCommitColor(deltaCache, commitId);
264
-
265
- return h(CommitPreview, {
266
- commit,
267
- color,
268
- onClick: () => (scrollToCommitIndex(commits.indexOf(commit)), setSelectedCommitId(commitId))
269
- })
270
- })),
271
- h('dt', {}, 'Missed'),
272
- h('dd', {}, deltaCache.thread.missed.map(commitId => {
273
- const commit = deltaCache.all.get(commitId);
274
- if (!commit)
275
- return null;
276
- const color = getCommitColor(deltaCache, commitId);
277
-
278
- return h(CommitPreview, {
279
- commit,
280
- color,
281
- onClick: () => (scrollToCommitIndex(commits.indexOf(commit)), setSelectedCommitId(commitId))
282
- })
283
- })),
284
- ])
285
- ]),
286
- h('hr'),
287
- selectedCommitDetails && [
288
- h(CommitPreview, {
289
- commit: selectedCommitDetails.commit,
290
- color: getCommitColor(deltaCache, selectedCommitDetails.commit.id),
291
- onClick: () => (scrollToCommitIndex(commits.indexOf(selectedCommitDetails.commit)), setSelectedCommitId(selectedCommitDetails.commit.id))
292
- }),
293
- h('button', { onClick: () => {
294
- setInsightState(state => {
295
- const prev = state.commitBreakpoints;
296
- if (prev.has(selectedCommitDetails.commit.id)) {
297
- prev.delete(selectedCommitDetails.commit.id)
298
- return { ...state, commitBreakpoints: new Set(prev) };
299
- }
300
- prev.add(selectedCommitDetails.commit.id)
301
- return { ...state, commitBreakpoints: new Set(prev) }
302
- })
303
- }}, 'Toggle Breakpoint'),
304
- h('h3', {}, 'Parent'),
305
- (() => {
306
- const parentId = selectedCommitDetails.commit.parent;
307
- if (!parentId)
308
- return 'NO PARENT';
309
- const parent = deltaCache.all.get(parentId);
310
- if (!parent)
311
- return h(CommitAttributeTag, { name: 'ParentID', value: parentId.toString() });
312
-
313
- return h(CommitPreview, {
314
- commit: parent,
315
- color: getCommitColor(deltaCache, parent.id),
316
- onClick: () => (scrollToCommitIndex(commits.indexOf(parent)), setSelectedCommitId(parent.id))
317
- });
318
- })(),
319
- h('h3', {}, 'Props'),
320
- h('ul', {},
321
- Object.entries(selectedCommitDetails.props).map(([prop, value]) => {
322
- return h('li', {}, `${prop} = ${getTextForValue(value)}`);
323
- })
324
- )
325
- ]
326
- ])
327
- ])
328
- ])
329
- }
330
-
331
-
332
- export const getTextForValue = (value: ValueReport): string => {
333
- switch (value.type) {
334
- case 'primitive':
335
- switch (typeof value.value) {
336
- case 'object':
337
- return `null`;
338
- case 'string':
339
- case 'boolean':
340
- case 'number':
341
- return value.value.toString();
342
- }
343
- case 'complex':
344
- return value.name;
345
- case 'undefined':
346
- return `undefined`;
347
- default:
348
- return value;
349
- }
350
- }
351
-
352
- const getCommitColor = (deltaCache: ThreadLookupCache, commitId: CommitID) => {
353
-
354
- const color =
355
- (deltaCache.nextTask && deltaCache.nextTask.id === commitId) ? '#e1d600ff'
356
- : deltaCache.targets.has(commitId) ? '#db55e7ff'
357
- : deltaCache.allTasks.has(commitId) ? '#ea931aff'
358
- : deltaCache.created.has(commitId) ? (deltaCache.prevTask && deltaCache.prevTask.id === commitId ? '#4bc847ff' : '#21a51cff')
359
- : deltaCache.removed.has(commitId) ? '#f25252ff'
360
- : deltaCache.updated.has(commitId) ? '#1ab9eaff'
361
- : deltaCache.visited.has(commitId) ? '#6f6f97ff'
362
- : '#cacaca';
363
-
364
- return color;
365
- }
@@ -1,18 +0,0 @@
1
- .modeButton {
2
- flex: 1;
3
- }
4
-
5
- .menuBar {
6
- margin: 0;
7
- padding: 0;
8
-
9
- display: flex;
10
- flex-direction: row;
11
-
12
- list-style: none;
13
- }
14
-
15
- .menuBarEntry {
16
- display: flex;
17
- flex: 1;
18
- }
package/MenuBar.ts DELETED
@@ -1,39 +0,0 @@
1
- import { Component, h } from "@lukekaalim/act";
2
- import { InsightMode } from "./mode";
3
- import { hs } from "@lukekaalim/act-web";
4
-
5
- import classes from './MenuBar.module.css';
6
-
7
- export type MenuBarProps = {
8
- currentMode: InsightMode,
9
- onSelectMode: (mode: InsightMode) => unknown,
10
- }
11
-
12
- export const MenuBar: Component<MenuBarProps> = ({ currentMode, onSelectMode }) => {
13
- return hs('menu', { className: classes.menuBar }, [
14
- hs('li', { className: classes.menuBarEntry },
15
- h(ModeButton, { onSelectMode, currentMode, mode: 'tree' }, 'Tree')),
16
- hs('li', { className: classes.menuBarEntry },
17
- h(ModeButton, { onSelectMode, currentMode, mode: 'thread' }, 'Thread')),
18
- hs('li', { className: classes.menuBarEntry },
19
- h(ModeButton, { onSelectMode, currentMode, mode: 'reports' }, 'Reports')),
20
- ])
21
- };
22
-
23
- type ModeButtonProps = {
24
- mode: InsightMode,
25
- currentMode: InsightMode,
26
- onSelectMode: (mode: InsightMode) => unknown,
27
- }
28
- const ModeButton: Component<ModeButtonProps> = ({ currentMode, mode, children, onSelectMode }) => {
29
- const selected = mode === currentMode;
30
- const onClick = () => {
31
- onSelectMode(mode);
32
- };
33
-
34
- return hs('button', {
35
- className: [classes.modeButton, selected && classes.selected].join(' '),
36
- onClick,
37
- disabled: selected
38
- }, children);
39
- }
@@ -1,61 +0,0 @@
1
- import { Component, h, useEffect, useState } from '@lukekaalim/act';
2
- import { ReconcilerDebugController, ReconcilerDebugEventBus, ScheduleController, ScheduleEventBus } from '@lukekaalim/act-debug';
3
- import { InsightAppState } from './InsightApp';
4
-
5
- export type ScheduleControlsProps = {
6
- controller: ScheduleController,
7
- bus: ScheduleEventBus,
8
-
9
- reconciler: ReconcilerDebugController,
10
-
11
- state: InsightAppState,
12
- onStateChange?: (newState: InsightAppState) => void,
13
- };
14
-
15
- export const ScheduleControls: Component<ScheduleControlsProps> = ({ controller, bus, reconciler, state, onStateChange = () => {} }) => {
16
- useEffect(() => {
17
- bus.onInterceptStart = () => {
18
- onStateChange({ ...state, paused: true });
19
- //onPauseChange(false)
20
- }
21
- bus.onInterceptEnd = () => {
22
- onStateChange({ ...state, paused: false });
23
- //onPauseChange(false)
24
- }
25
- bus.onAfterCallbackExecute = () => {
26
- //reconciler.getThread();
27
- }
28
- }, [bus, reconciler, state])
29
-
30
-
31
- const onStepClick = () => {
32
- controller.step();
33
- }
34
- const onResumeClick = () => {
35
- controller.cancelIntercept();
36
- }
37
- const onChangeBreakBeforeUpdate = (event: Event) => {
38
- onStateChange({ ...state, breakOnBeforeUpdate: (event.target as HTMLInputElement).checked });
39
- }
40
- const onChangeBreakAfterUpdate = (event: Event) => {
41
- onStateChange({ ...state, breakOnAfterUpdate: (event.target as HTMLInputElement).checked });
42
- }
43
-
44
- return h('div', { style: { background: state.paused ? 'red' : 'white', padding: '8px', display: 'flex', gap: '12px' }}, [
45
- h('div', { style: { display: 'flex', 'flex-direction': 'column' } }, [
46
- h('label', { style: { 'margin': 'auto 0' } }, [
47
- h('span', {}, `Break Before Update`),
48
- h('input', { type: 'checkbox', checked: state.breakOnBeforeUpdate, onChange: onChangeBreakBeforeUpdate }),
49
- ]),
50
- h('label', { style: { 'margin': 'auto 0' } }, [
51
- h('span', {}, `Break After Update`),
52
- h('input', { type: 'checkbox', checked: state.breakOnAfterUpdate, onChange: onChangeBreakAfterUpdate }),
53
- ]),
54
- ]),
55
- h('button', { onClick: onStepClick, disabled: !state.paused, style: { padding: '8px' } }, 'Step'),
56
- h('button', { onClick: onResumeClick, disabled: !state.paused, style: { padding: '8px' } }, 'Resume'),
57
- h('span', {
58
- style: { border: `2px solid ${state.paused ? 'orange' : 'black'}`, 'border-radius': '8px', padding: '8px' }
59
- }, state.paused ? `Paused` : `Ready`),
60
- ])
61
- };
package/lookup.ts DELETED
@@ -1,185 +0,0 @@
1
- import { CommitReport, DeltaReport, ElementReport, ThreadReport, TreeReport, WorkTaskReport } from "@lukekaalim/act-debug";
2
- import { CommitID, CommitVersion, WorkThread2 } from "@lukekaalim/act-recon";
3
-
4
- export class MutableCommitRef {
5
- element: ElementReport;
6
- id: CommitID;
7
- version: CommitVersion;
8
- distance: number;
9
-
10
- report: CommitReport;
11
-
12
- children: MutableCommitRef[] = [];
13
- parent: null | MutableCommitRef = null;
14
-
15
- constructor(commit: CommitReport) {
16
- this.element = commit.element;
17
- this.id = commit.id;
18
- this.version = commit.version;
19
- this.distance = commit.distance;
20
-
21
- this.report = commit;
22
- }
23
-
24
- update(commit: CommitReport) {
25
- this.report = commit;
26
- this.version = commit.version;
27
- this.element = commit.element;
28
- }
29
-
30
- resolve(lookupMap: Map<CommitID, MutableCommitRef>) {
31
- if (this.report.parent)
32
- this.linkParent(this.report.parent, lookupMap);
33
- this.linkChildren(this.report.children, lookupMap);
34
- }
35
-
36
- linkParent(parent: CommitID, lookupMap: Map<CommitID, MutableCommitRef>) {
37
- this.parent = lookupMap.get(parent) || null;
38
- }
39
- linkChildren(children: CommitID[], lookupMap: Map<CommitID, MutableCommitRef>) {
40
- this.children = children.map(c => lookupMap.get(c)).filter(x => !!x);
41
- }
42
- }
43
-
44
- export class CommitLookupCache {
45
- map: Map<CommitID, CommitReport> = new Map();
46
- roots: Set<CommitID> = new Set();
47
-
48
- setTree(tree: TreeReport) {
49
- this.map.clear();
50
- this.roots.clear();
51
-
52
- for (const commit of tree.commits) {
53
- this.map.set(commit.id, commit)
54
- if (!commit.parent)
55
- this.roots.add(commit.id);
56
- }
57
- }
58
-
59
- ingest(delta: DeltaReport) {
60
- for (const create of delta.created) {
61
- this.map.set(create.id, create);
62
- if (!create.parent)
63
- this.roots.add(create.id);
64
- }
65
- for (const update of delta.updated)
66
- this.map.set(update.id, update);
67
- for (const remove of delta.removed) {
68
- this.map.delete(remove.id);
69
- this.roots.delete(remove.id);
70
- }
71
- }
72
- }
73
-
74
- /**
75
- * A bunch of relevant data for a Tree in the progress of changing
76
- */
77
- export class ThreadLookupCache {
78
- canon: CommitLookupCache;
79
-
80
- report: DeltaReport | null = null;
81
- thread: ThreadReport | null = null;
82
-
83
- constructor(canon: CommitLookupCache) {
84
- this.canon = canon;
85
- }
86
-
87
- roots: Set<CommitID> = new Set();
88
-
89
- created: Set<CommitID> = new Set();
90
- updated: Set<CommitID> = new Set();
91
- removed: Set<CommitID> = new Set();
92
-
93
- /**
94
- * An up to date map of the tree, plus deleted notes in this delta
95
- */
96
- all: Map<CommitID, CommitReport> = new Map();
97
-
98
- nextTask: WorkTaskReport | null = null;
99
- prevTask: WorkTaskReport | null = null;
100
-
101
- allTasks: Map<CommitID, WorkTaskReport> = new Map();
102
-
103
- targets: Set<CommitID> = new Set();
104
- visited: Set<CommitID> = new Set();
105
-
106
- /**
107
- * Clear the delta cache
108
- */
109
- reset() {
110
- this.roots = new Set(this.canon.roots)
111
- this.all = new Map(this.canon.map);
112
- this.allTasks = new Map();
113
-
114
- this.nextTask = null;
115
- this.prevTask = null;
116
- this.report = null;
117
-
118
- this.created.clear();
119
- this.updated.clear();
120
- this.removed.clear();
121
-
122
- this.targets.clear();
123
- this.visited.clear();
124
- }
125
-
126
- ingestThread(thread: ThreadReport) {
127
- this.thread = thread;
128
-
129
- this.nextTask = thread.pendingTasks[thread.pendingTasks.length - 1];
130
- this.targets = new Set(thread.reasons.map(reason => reason.target));
131
- this.visited = new Set(thread.visited)
132
- this.allTasks = new Map(thread.pendingTasks.map(task => [task.id, task]))
133
- }
134
-
135
- ingestDelta(delta: DeltaReport) {
136
- this.report = delta;
137
- const createdIds = new Set(delta.created.map(c => c.id));
138
-
139
- for (const commit of delta.created) {
140
- this.created.add(commit.id)
141
-
142
- const children = [...new Set(commit.children.filter(c => this.all.has(c) || createdIds.has(c)))]
143
- this.all.set(commit.id, { ...commit, children });
144
-
145
- if (!commit.parent)
146
- this.roots.add(commit.id);
147
- }
148
- for (const commit of delta.updated) {
149
- const existingCommit = this.canon.map.get(commit.id) as CommitReport;
150
-
151
- const children = [...new Set([
152
- ...commit.children.filter(c => this.all.has(c)),
153
- ...existingCommit.children,
154
- ])]
155
- const mergedCommitReport = { ...commit, children };
156
-
157
- this.updated.add(commit.id)
158
- this.all.set(commit.id, mergedCommitReport)
159
- }
160
- for (const commit of delta.removed) {
161
- this.removed.add(commit.id);
162
- this.all.set(commit.id, commit);
163
- }
164
- }
165
-
166
- getFlat() {
167
- const pending: CommitReport[] = [...this.roots.values()]
168
- .map(root => this.all.get(root))
169
- .filter(x => !!x);
170
-
171
- const flat: CommitReport[] = [];
172
-
173
- while (pending.length > 0) {
174
- const commit = pending.pop() as CommitReport;
175
- flat.push(commit);
176
- for (const childId of [...commit.children].reverse()) {
177
- const child = this.all.get(childId);
178
- if (child)
179
- pending.push(child);
180
- }
181
- }
182
-
183
- return flat;
184
- }
185
- }