Replies: 1 comment
-
Having dependency injection built in would be amazing! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR: What it is
Why it is necessary
adapter-static
enjoyer I abuseload
functions to do this but it is not semantically coherent.I am accessing services through a prop called
data
that the docs say should hold data, not services.I also don't like abusing APIs like this because I know other devs will copy it without fully understanding its implications, things will break because they use
adapter-node
and they will proceed as explained in the following point.RubeGoldberg2
then calling the staticapply
method on it but the team lead says we should use theRubeGoldberg4
class as theRubeGoldberg
class was deprecated many years ago due to the many bugs it contains. Unfortunately theRubeGoldberg4
class does not support your use-case yet so you may want to useRubeGoldberg3V2
and change it when we updateRubeGoldberg4
, just make sure you delete the "DO_NOT_USE_RG3V2_OR_YOU_WILL_BE_FIRED" global variable immediately after calling theapply
method because there is a test in CI that will break" . Standardization and normalization is specially useful for ai-generated code: less different ways to do a thing leads to better ai-generated code that the devs can actually understand and reason about instead of blindly accepting whatever slop the ai spits.load
functions return types).How it works
Similarly to
load
functions, values returned by stacked contexts are merged, andload
functions have access to the value resulting from their siblingcontext
function (merged with parent contexts).+*.server.ts
files do not share context nor context type with non+*.server.ts
files and vice-versa.+page.svelte
and+layout.svelte
get acontext
prop along withdata
, thecontext
prop always refers to "universal" context in.svelte
files as it makes no sense to refer to the server context there. The server context is meant for the server only.Symbol.dispose
andSymbol.asyncDispose
are both called (if defined) when we navigate away from the corresponding page/layout so we can clean the mess (e.g: gracefully closing ws, clearing somelocalStorage
keys used only to persist some form state, removing global event listeners, etc.).Docs
First of all note that I only use
adapter-static
so I might be missing some edge cases here.Docs should show a very big and red warning stating that server and client context are separate so doing
context.clicked+=1
inside an onclick handler will not magically update the value ofcontext.clicked
in the server.Docs should recommend using pure context functions.
Docs should discourage returning context data from load functions.
What about the current thing called context in svelte
I only have negative opinions in regard to that context.
I have never used it and I don't think I ever will. I even prefer using load functions for context management to using the existing context API.
Some of those my opinions against the current context API are:
getContext('key')
. I am too dumb to remember what I named my contexts and too lazy to type their full names as strings. I want to write a letter and hit autocomplete to access my context. I want my context to be strongly typed out of the box so I can keep hitting autocomplete without ending up calling some service that is not really there or has not been initialized or even getting no context at all because I mispelled the context name.account
service on a layout meant for authenticated users so it includes methods only available to those users).Beta Was this translation helpful? Give feedback.
All reactions