Skip to content

Instantly share code, notes, and snippets.

@robertsosinski
Created October 17, 2024 20:25
Show Gist options
  • Save robertsosinski/ccbcd40d2235e30e68817748784170f7 to your computer and use it in GitHub Desktop.
Save robertsosinski/ccbcd40d2235e30e68817748784170f7 to your computer and use it in GitHub Desktop.
VSCode Astro Error Example
<app-complex-time>
<button>click</button>
<div class="target"></div>
</app-complex-time>
<script>
import {actions} from "astro:actions";
class AppComplexTime extends HTMLElement {
async connectedCallback() {
const button = this.querySelector('button');
const target = this.querySelector('div.target');
button.addEventListener('click', async () => {
let input = {x: 1, y: 2};
const { data, error } = await actions.add(input);
if (error) {
target.innerHTML = "error";
} else {
target.innerHTML = data.sum.toString();
}
});
}
}
customElements.define('app-complex-time', AppComplexTime);
</script>
import {defineAction} from 'astro:actions';
import {z} from "astro:schema";
export const server = {
add: defineAction({
input: z.object({
x: z.number(),
y: z.number()
}),
handler: async ({x, y}) => {
let sum = x + y;
return {sum};
}
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment