Skip to content

Commit

Permalink
include signal in event properties
Browse files Browse the repository at this point in the history
  • Loading branch information
martrapp committed May 4, 2024
1 parent 4a55ca6 commit 7b01d59
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-fireants-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-vtbot": patch
---

VtBotDebug: include new signal property in event properties.
15 changes: 12 additions & 3 deletions components/VtBotDebug.astro
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ const active = import.meta.env.DEV || production;
async function delta(e: Record<string, any>, prop: string, deltaOnly = false) {
const _vtbot_debug = window._vtbot_debug;
let bold = (s: string) => `**${s}**`;
let deref = (x: any) => x;
let print = (x: any) => x;
let value = (x: any) => x;
let deref = (x: any) => x; // map value from properties
let print = (x: any) => x; // pretty print value
let value = (x: any) => x; // comaprison for difference

if (prop === 'to' || prop === 'from') {
deref = (x) => x?.href;
Expand All @@ -112,6 +112,14 @@ const active = import.meta.env.DEV || production;
} else if (prop === 'swap' || prop === 'loader') {
print = (x) => (x ? x.toString() : '(null)');
bold = (x) => x + '\n';
} else if (prop === 'signal') {
print = (x) => {
if (x.aborted) {
return `aborted${x.reason ? ' (' + x.reason + ')' : ''}${x.onabort ? ': ' + x.onabort.toString + '\n' : ''}`;
}
return `not aborted ${x.onabort ? ': ' + x.onabort.toString + '\n' : ''}`;
};
deref = print;
}

let different = () => value(deref(_vtbot_debug.capture[prop])) !== value(deref(e[prop]));
Expand Down Expand Up @@ -157,6 +165,7 @@ const active = import.meta.env.DEV || production;
delta(e, 'navigationType', deltaOnly);
delta(e, 'info', deltaOnly);
delta(e, 'newDocument', deltaOnly);
delta(e, 'signal', deltaOnly);
if (isTransitionBeforePreparationEvent(e)) {
delta(e, 'formData', deltaOnly);
delta(e, 'loader', deltaOnly);
Expand Down
Empty file added test/fixture/public/main.css
Empty file.
2 changes: 1 addition & 1 deletion test/fixture/src/pages/debug/debug1.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import VtBotDebug from 'astro-vtbot/components/VtBotDebug.astro';

<Layout title="Debug1">
<VtBotDebug slot="head" />
<link rel="stylesheet" href="https://w3schools.com/lib/topnav/main.css" slot="head" />
<link rel="stylesheet" href="http://127.0.0.1:4321/main.css" slot="head" />

<h1>Debug 1</h1>
<p><a id="debug2" href="/debug/debug2/">Goto Page 2</a></p>
Expand Down

0 comments on commit 7b01d59

Please sign in to comment.