Crafting the Web with Precision: Expert in Performance, Code Quality who cares about Accessibility. Self-taught with 20+ years of professional experience
Bookmarking.
I wonder the use-case and usage context.
At first glance it looks like something related to HTTP server middleware, and/or at leadt Node.js runtime side.
If that's the case, in KoaJS, there's ctx.state, and Express has locals and some way of abstracting/storing state such as shoring in a cookie or external, like koa-session does.
Before (ECMAScript 5) we had to use magic names and enumeration, then we got defineProperties. There are a few implementation of that idea. Now that Proxy is more common, it's great.
You are right, it's pretty like response.locals in Express (app.locals are really rather global), I haven't used KoaJS. The difference being that you don't have to pass response through to every function you call as cls is defined as a require.
Crafting the Web with Precision: Expert in Performance, Code Quality who cares about Accessibility. Self-taught with 20+ years of professional experience
Koa with ctx.state is unique per request per user. Look the source up, it's great. I prefer it to Express. It's actually from some folks from Express. But the API is more modern. I imagine that Express 5 (in beta?) is inspired by it
Looks from the docs that you are still supposed to pass it on though? It's not a global like cls unless I'm missing something. If that's the case then you put it in cls and never pass it through function layers, callback and events etc.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Bookmarking.
I wonder the use-case and usage context.
At first glance it looks like something related to HTTP server middleware, and/or at leadt Node.js runtime side.
If that's the case, in KoaJS, there's ctx.state, and Express has locals and some way of abstracting/storing state such as shoring in a cookie or external, like koa-session does.
Before (ECMAScript 5) we had to use magic names and enumeration, then we got defineProperties. There are a few implementation of that idea. Now that Proxy is more common, it's great.
Gotta get back to this
You are right, it's pretty like
response.locals
in Express (app.locals are really rather global), I haven't used KoaJS. The difference being that you don't have to passresponse
through to every function you call as cls is defined as a require.Koa with ctx.state is unique per request per user. Look the source up, it's great. I prefer it to Express. It's actually from some folks from Express. But the API is more modern. I imagine that Express 5 (in beta?) is inspired by it
Looks from the docs that you are still supposed to pass it on though? It's not a global like cls unless I'm missing something. If that's the case then you put it in cls and never pass it through function layers, callback and events etc.