-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba58f66
commit 9676f91
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function (req, res) { | ||
return res.json( | ||
Array.from({ length: 3 }) | ||
.fill(0) | ||
.map((d, i) => (i + 1) * Math.random()) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { signal } from '@preact/signals' | ||
import { useEffect } from 'preact/hooks' | ||
|
||
const data$ = signal([]) | ||
|
||
async function fetchData() { | ||
const data = await fetch('/api/random-data').then(d => d.json()) | ||
data$.value = data | ||
} | ||
|
||
export function Triggerer() { | ||
useEffect(() => { | ||
fetchData() | ||
}, []) | ||
return ( | ||
<div class="p-10 border border-red-400 border-dashed"> | ||
<h2>Triggerer Island</h2> | ||
<button class="px-4 py-2 text-white bg-black rounded-md" onClick={fetchData}>Fetch Again</button> | ||
</div> | ||
) | ||
} | ||
|
||
export function Renderer() { | ||
return ( | ||
<div class="p-10 border border-blue-400 border-dashed"> | ||
<h2>Renderer Island</h2> | ||
<ul> | ||
{data$.value.map(d => ( | ||
<li>{d}</li> | ||
))} | ||
</ul> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Renderer, Triggerer } from '../components/SharedSignal.js' | ||
|
||
export default function SharedSignal() { | ||
return ( | ||
<div class="flex flex-col gap-2 p-10"> | ||
<Triggerer /> | ||
<Renderer /> | ||
</div> | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.