diff --git a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/PreactCounter.tsx b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/PreactCounter.tsx index e85acf3883..dc5ed0ad72 100644 --- a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/PreactCounter.tsx +++ b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/PreactCounter.tsx @@ -1,18 +1,24 @@ import { h } from 'preact'; import { getContext } from '@astrojs/store'; import { useStore } from '@astrojs/preact/store'; +import { decrement, increment } from '../stores/counter'; +import type { Writable } from '@astrojs/store'; +import type { CounterState } from '../stores/counter'; /** a counter written in Preact */ export function PreactCounter({ children, id }) { - const counter = getContext('counter'); + const counter = getContext>('counter'); const state = useStore(counter); + + const onDecrement = () => decrement(counter); + const onIncrement = () => increment(counter); return ( <>
- +
{state.count}
- +
{children}
diff --git a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/ReactCounter.jsx b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/ReactCounter.jsx index 41f0772e9d..4ac59c2a4c 100644 --- a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/ReactCounter.jsx +++ b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/ReactCounter.jsx @@ -1,18 +1,22 @@ import { React } from 'react'; import { getContext } from '@astrojs/store'; import { useStore } from '@astrojs/react/store'; +import { decrement, increment } from '../stores/counter'; /** a counter written in React */ export function Counter({ children, id }) { const counter = getContext('counter'); const state = useStore(counter); + const onDecrement = () => decrement(counter); + const onIncrement = () => increment(counter); + return ( <>
- +
{state.count}
- +
{children}
diff --git a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/SolidCounter.tsx b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/SolidCounter.tsx index 9174d96f7b..a62f3fcf2e 100644 --- a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/SolidCounter.tsx +++ b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/SolidCounter.tsx @@ -1,21 +1,27 @@ import { createSignal } from 'solid-js'; import { getContext } from '@astrojs/store'; import { useStore } from '@astrojs/solid-js/store'; +import { decrement, increment } from '../stores/counter'; +import type { Writable } from '@astrojs/store'; +import type { CounterState } from '../stores/counter'; /** a counter written with Solid */ export default function SolidCounter({ children, id }) { // TODO: Astro can't resolve the renderer without this? const test = createSignal(0); - const counter = getContext('counter'); + const counter = getContext>('counter'); const state = useStore(counter); + const onDecrement = () => decrement(counter); + const onIncrement = () => increment(counter); + return ( <>
- +
{state().count}
- +
{children}
diff --git a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/SvelteCounter.svelte b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/SvelteCounter.svelte index 7d21a72033..f6ca7ee612 100644 --- a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/SvelteCounter.svelte +++ b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/SvelteCounter.svelte @@ -2,17 +2,21 @@
- +
{ $state.count }
- +
diff --git a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/VueCounter.vue b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/VueCounter.vue index 7f58f896df..128f1c8d06 100644 --- a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/VueCounter.vue +++ b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/components/VueCounter.vue @@ -12,6 +12,7 @@ diff --git a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/stores/counter.ts b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/stores/counter.ts index 0a9d44b102..233ace56c4 100644 --- a/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/stores/counter.ts +++ b/packages/astro/e2e/fixtures/multiple-frameworks-stores/src/stores/counter.ts @@ -1,26 +1,8 @@ -import { Readable, writable, store } from '@astrojs/store'; +import { Writable } from '@astrojs/store'; export interface CounterState { count: number; } -export interface CounterStore extends Readable { - increment(): void; - decrement(): void; - reset(): void; -} - -export default function createCounter(initial: CounterState = { count: 0 }): CounterStore { - const { subscribe, set, update } = store(initial); - - return { - subscribe, - increment: () => update(({ count }) => ({ - count: count + 1 - })), - decrement: () => update(({ count }) => ({ - count: count - 1 - })), - reset: () => set({ count: 0 }) - } -} +export const decrement = (store: Writable) => store.update(({ count }) => ({ count: count - 1 })); +export const increment = (store: Writable) => store.update(({ count }) => ({ count: count + 1 }));