eluvatar,

Kinda wish it had DI, coming from Angular and C# it’s so helpful to have stateful services, I know one answer is to just use a global static, but that causes huge issues on the server side and it’s really easy to make mistakes there. It feels like contexts are the answer, but then you can’t use those services in load functions.

I’m curious where do you store the current user data. In a static store? Return it from a load function and access it via the page store? Somewhere else?

silas, (edited )
@silas@programming.dev avatar

Well, I usually fetch and return user data from a top-level +layout.js or +layout.server.js. Then my user data is always available in every layout or page through the data prop (and types are all handle automatically for this too).

I then invalidate and re-fetch that data using invalidate(), invalidateAll(), and depends() if the user data becomes stale.

Any state/data from the user that needs to stay server-side (like tokens) I keep in event.locals which is available in all .server.js files

andrewbrey,

I really like how with React (and a few others) you can make a quick abstraction in the same file for a repeated chunk of the render. Sometimes something warrants pulling out into a function for reusability but it doesn’t quite pass the bar to justify its own file as a component - I know there’s some template stuff coming in Svelte 5, so hopefully that scratches the itch.

silas,
@silas@programming.dev avatar

Totally agree, I can definitely say I’ve found myself wishing for that more as I continue to use Svelte. I didn’t see it as necessary at first, but situations that could benefit from that have come up enough now that I’ve used it for a while

mac,
@mac@infosec.pub avatar

This seems to now be possible thanks to Svelte 5 Snippets

silas,
@silas@programming.dev avatar

Oh wow, thanks for sharing. Hadn’t heard of that yet, it definitely makes it possible but that syntax will take some getting used to

  • All
  • Subscribed
  • Moderated
  • Favorites
  • sveltejs@programming.dev
  • DreamBathrooms
  • mdbf
  • tacticalgear
  • magazineikmin
  • thenastyranch
  • rosin
  • everett
  • Youngstown
  • khanakhh
  • slotface
  • ngwrru68w68
  • kavyap
  • cisconetworking
  • InstantRegret
  • megavids
  • osvaldo12
  • GTA5RPClips
  • ethstaker
  • tester
  • Durango
  • normalnudes
  • anitta
  • modclub
  • cubers
  • Leos
  • provamag3
  • JUstTest
  • lostlight
  • All magazines