-
-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathUpdateItem.tsx
More file actions
88 lines (82 loc) · 2.42 KB
/
Copy pathUpdateItem.tsx
File metadata and controls
88 lines (82 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { SignalUpdate } from "../types";
interface UpdateItemProps {
update: SignalUpdate;
}
export function UpdateItem({ update }: UpdateItemProps) {
const time = new Date(
update.timestamp || update.receivedAt
).toLocaleTimeString();
const depth = " ".repeat(update.depth || 0);
const formatValue = (value: any): string => {
if (value === null) return "null";
if (value === undefined) return "undefined";
if (typeof value === "string") return `"${value}"`;
if (typeof value === "function") return "function()";
if (typeof value === "object") {
try {
return JSON.stringify(value, null, 0);
} catch {
return "[Object]";
}
}
return String(value);
};
if (update.type === "effect") {
return (
<div
style={{ marginLeft: `${(update.depth || 0) * 4}px` }}
className={`update-item ${update.type}`}
>
<div className="update-header">
<span className="signal-name">
{depth}↪️ {update.signalName}
{update.componentNames && update.componentNames.length > 0 && (
<ul class="component-list">
<span class="component-name-header">Rerendered</span>
{update.componentNames?.map((componentName, i) => (
<li key={componentName} class="component-name">
{componentName}
{i < update.componentNames!.length - 1 ? ", " : ""}
</li>
))}
</ul>
)}
</span>
<span className="update-time">{time}</span>
</div>
</div>
);
}
const prevValue = formatValue(update.prevValue);
const newValue = formatValue(update.newValue);
return (
<div
style={{ marginLeft: `${(update.depth || 0) * 4}px` }}
class={`update-item ${update.type}`}
>
<div class="update-header">
<span class="signal-name">
{depth}
{update.depth === 0 ? "🎯" : "↪️"} {update.signalName}
</span>
<span class="update-time">{time}</span>
</div>
<div class="value-change">
<span class="value-prev">{prevValue}</span>
<span class="value-arrow">→</span>
<span class="value-new">{newValue}</span>
</div>
{update.componentNames && update.componentNames.length > 0 && (
<ul class="component-list">
<span class="component-name-header">Rerendered</span>
{update.componentNames?.map((componentName, i) => (
<li key={componentName} class="component-name">
{componentName}
{i < update.componentNames!.length - 1 ? ", " : ""}
</li>
))}
</ul>
)}
</div>
);
}