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-staticenjoyer I abuseloadfunctions to do this but it is not semantically coherent.I am accessing services through a prop called
datathat 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-nodeand they will proceed as explained in the following point.RubeGoldberg2then calling the staticapplymethod on it but the team lead says we should use theRubeGoldberg4class as theRubeGoldbergclass was deprecated many years ago due to the many bugs it contains. Unfortunately theRubeGoldberg4class does not support your use-case yet so you may want to useRubeGoldberg3V2and 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 theapplymethod 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.loadfunctions return types).How it works
Similarly to
loadfunctions, values returned by stacked contexts are merged, andloadfunctions have access to the value resulting from their siblingcontextfunction (merged with parent contexts).+*.server.tsfiles do not share context nor context type with non+*.server.tsfiles and vice-versa.+page.svelteand+layout.svelteget acontextprop along withdata, thecontextprop always refers to "universal" context in.sveltefiles as it makes no sense to refer to the server context there. The server context is meant for the server only.Symbol.disposeandSymbol.asyncDisposeare 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 somelocalStoragekeys used only to persist some form state, removing global event listeners, etc.).Docs
First of all note that I only use
adapter-staticso 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+=1inside an onclick handler will not magically update the value ofcontext.clickedin 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.accountservice 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