Menu

Building Custom Context Decorators in KickJS
πŸ“°
0

Building Custom Context Decorators in KickJS

DEV CommunityΒ·Orinda Felix OchiengΒ·about 1 month ago
#0tMBL09u
#kickjs#typescript#node#locale#contributor#fullscreen
Reading 0:00
15s threshold

In Express you reach for req.locale = ... inside a middleware and hope the downstream handler remembers what type it is. KickJS gives you a better home for that data: a context decorator . You declare the key once, write a typed resolve(ctx) function, register it at the scope it belongs to, and every handler in that scope can call ctx.get('locale') with full type safety. Anything you'd hang off req β€” request id, locale, the audit actor, feature flags, an idempotency key β€” should live here instead. This article is the field guide: the two factories, the full options surface, the five registration scopes and how they fight, how to read values back from handlers and services, the boot-time errors you should know on sight, and three patterns worth stealing. The two factories KickJS ships two factories, and the difference is whether your resolver needs to see the HTTP request. defineHttpContextDecorator is for HTTP routes.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More