feat: more advanced prop serializer for islands (#1224)
This commit adds support for an advanced (de)serializer that is used for page state (island props and plugin state). This new serializer supports maintaining references (thus supporting circular objects, and multi-referenced objects). This is a pre-requisite for allowing to pass signals, JSX, Uint8Arrays, Date, and many other "advanced" values.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState } from "preact/hooks";
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
import { RoundedButton } from "../components/Button.tsx";
|
||||
import { IconMinus, IconPlus } from "../components/Icons.tsx";
|
||||
@@ -8,20 +8,20 @@ interface CounterProps {
|
||||
}
|
||||
|
||||
export default function Counter(props: CounterProps) {
|
||||
const [count, setCount] = useState(props.start);
|
||||
const count = useSignal(props.start);
|
||||
return (
|
||||
<div class="bg-gray-100 p-4 border border-gray-200 flex items-center justify-around">
|
||||
<RoundedButton
|
||||
title="Subtract 1"
|
||||
onClick={() => setCount(count - 1)}
|
||||
disabled={!IS_BROWSER || count <= 0}
|
||||
onClick={() => count.value -= 1}
|
||||
disabled={!IS_BROWSER || count.value <= 0}
|
||||
>
|
||||
<IconMinus />
|
||||
</RoundedButton>
|
||||
<div class="text-3xl tabular-nums">{count}</div>
|
||||
<RoundedButton
|
||||
title="Add 1"
|
||||
onClick={() => setCount(count + 1)}
|
||||
onClick={() => count.value += 1}
|
||||
disabled={!IS_BROWSER}
|
||||
>
|
||||
<IconPlus />
|
||||
|
||||
Reference in New Issue
Block a user