-
-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(context): Introduce ContextVariableMap. #429
Conversation
c30b87f
to
e46c2c1
Compare
e46c2c1
to
a5d4d3b
Compare
@@ -7,6 +7,8 @@ import { METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE } from './router' | |||
import { TrieRouter } from './router/trie-router' // Default Router | |||
import { getPathFromURL, mergePath } from './utils/url' | |||
|
|||
export interface ContextVariableMap {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget the specifics, but this should probably extend Record<string, any>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR, there is no need to extend Record<string, any>
since ContextVariableMap
is a type for type definition and no object is created. (This is like HTMLElementTagNameMap.)
Also, not extending Record<string, any>
will give better completion results.
src/context.ts
Outdated
@@ -20,7 +20,10 @@ export interface Context<RequestParamKeyType extends string = string, E = Env> { | |||
header: (name: string, value: string) => void | |||
status: (status: StatusCode) => void | |||
set: (key: string, value: any) => void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set should probably also attempt to enforce the type of value
if it's specified on ContextVariableMap
for extra type safety.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Fixed in 1852968.
Thank you! Looks good! |
Allows the user to type the value of
ctx.set('variable', var)
orctx.get('variable')
.This is one of the ideas to solve the #414 problem, but even if this were not used to solve #414, I think this would still be a useful feature.