Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include signal in event properties #123

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
5 changes: 2 additions & 3 deletions test/fixture/src/pages/debug/debug1.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import VtBotDebug from 'astro-vtbot/components/VtBotDebug.astro';
---

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

<VtBotDebug 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>
</Layout>
Loading