Signals & Data Fetching

1. Should I declare useSignal on route or island? 2. How to fetch data? Make an async route? Do useEffect?
A
anggoran20d ago
I'm kinda confused about the solution, since we can't declare useSignal within async route.
M
marvinh.20d ago
1. to declare a signal in an async route use:
const mySignal = signal(123)
const mySignal = signal(123)
The useSignal doesn't work because async routes are not components 2. Depends on where you want to fetch data. If on the server, fetch it in your route and pass it down. On the client, trigger fetch based on user interaction like on click or inside a useEffect
A
anggoran20d ago
in the tutorial it is stated that As a shortcut for combining a GET handler with a route, you can define your route as async. , so to fetch on server, async route and GET handler are the same?
M
marvinh.20d ago
yep
A
anggoran20d ago
alright, thank you very much!
M
mrk19d ago
Some thoughts: Would there be a reason to pass data wrapped in a signal from an async route to a client component/island? Reactivity is not carried over the wire and the server has no client/user interaction, so no need for reactivity there, right? I guess you where just answering for completeness @marvinh. , since signals are indeed serializable by fresh and sent over-the-wire. Just making sure I'm not missing out on some server signal use case 😃 This reminds me of a blogpost I read about Ryan Carniato where he hints on a future with server-to-client signals, that is, where reactivity trascends the server/client border. Maybe this could be done using WebSockets/SSE, definitively interesting...
M
marvinh.19d ago
Yeah the reactivity transcending across the server client boundary is something I'd love to explore more this year. I feel like that's the direction frameworks are moving towards. Creating a signal in an async route may still make sense if it is passed to different islands. Both islands will subscribe to the exact same signal in the client in this case.
M
mrk19d ago
Oh I see, so it does make sense as a great place to declare shared global signals for multiple islands to import 👌 ... And yeah, after using fresh for a while, the server-client boundary is what takes the most time to get used to and requires changing one's mental model (coming from SPA's myself at least). I see how this could hugely enhance DX if signal reactivity could cross this border. Apart from frameworks looking into these patterns, there's also SignalDB which accomplishes something similar (more like a Signals-based abstraction over arbitrary databases/datastores/apis), though it's framework agnostic. Might be of interest too 👍
More Posts
Error Using Google PubSub With DenoHi there, I am trying to work with PubSub using Deno. I am able to access and create new PubSub inDeno deploy IPHey! Is that possible to get the IP address of a deployment on Deno deploy? The backend we host theUbuntu Server HTTPSHow can I add https i Ubuntu Server to run Deno API over https? Without using Apache. I run deno coUse Deno as a type checker for a front-end project?Hey. I have a need to increase the speed of typechecking my frontend project. I'm not sure, but it sLogger Structure argsI am implementing a simple access log in Deno Fresh, but I am not quite sure how to use the standardAdd static font files as a fresh pluginHello! I'm creating a component library for Fresh. I'm in the part of setting up the plugin part of Compiling code breaks it (except on Linux)error: [ERR_MODULE_NOT_FOUND] Cannot find module "C:\Users\Eris\AppData\Local\Temp\deno-compile-llm-Interface with unknown amount of keys but all the same typeHow do i create an interface/type that can have unlimited keys but the values are all the same type?How to open a file as blob?Docs for Blob (https://deno.land/api@v1.42.0?s=Blob) say that `File` implements `Blob`. But the docsDeno deploy running my code multiple timesIm hosting a small discord bot on deno deploy but for some reason its firing the events multiple timvalue too large in kv (30kb)I'm getting a value too large error when setting a value in KV (on deploy) even though the value is How to work without a tsconfig.json in VSCode? Getting typescript errors due to React.``` Cannot find name 'Map'. Do you need to change your target library? Try changing the 'lib' compilupdate deno version on Alpineon alpine the version of deno is 1.38.1 https://pkgs.alpinelinux.org/packages?name=deno is there a rDeno blog deployment failureHi all, recently tried to make a new blog post on personal blog, however now the deployment fails (nFresh 1.6 - Deno Deploy - TailwindDeploying my project on deno deploy is not working. Does anyone have the same issue ? I am using taAnalyze dependencies for deno compileIs there a way to analyze the dependencies that is added when running deno compile? My compiled binaHow to install jupyter using deno v1.41.xAccording to the documentation https://docs.deno.com/runtime/manual/tools/jupyter the command shouldHelp with TypeScript namespaces - is this pattern supported?Hi! I am attempting to model some classes in a Namespace for organization purposes. I would expect t