mm-ninja-turtles / turtle-express

My attempt of making Express.JS a typesafe router with Zod.
3 stars 0 forks source link

[feature]: global context via createRouter function #36

Closed wai-lin closed 2 years ago

wai-lin commented 2 years ago

Currently there's is a per handler context provider.

There's a need for global context provider via createRouter() function and also router.path() function for per path context provider.

wai-lin commented 2 years ago

After some consideration, I'm quite biased about this. Will giving the global context is a good thing? I think we should take lesson from the vue2 option api's mixin problems. Especially for those who might be using turtle-express in javascript environment. Since they don't have type safety like typescript users they may not notice the naming collisions. The worst about the global context is where to track the error from. For example if there is a context value used inside a resolver is undefined or occur some kind of error, it'll be a context tracing hell (where the context is provided from).

I think just doing things the normal import export would be much nicer to trace back if something went wrong. Also users can just provide what they want from global object if they wanted.

wai-lin commented 2 years ago

I think I won't be doing this feature for the time being since I did not convince myself enough to do this. I think the problems out weight the benefits the context provide. Currently closing the issue.