Comments (3)
Hi, thanks!
I have considered this -- mostly in terms of routing. I've had this internal battle about it for Polka, too.
The problem is that decorator support is spotty & spooky to a large number of people still. It also raises a bunch of TS typing implications, which I've not really looked into as this is my first framework claiming 1st class TS support.
I don't want to say much about this right now, but I will mention that I've been toying around with compile-time optimizations. So, again with routing, the regexparam
code should/will not be in the generated bundle at all. Most of the router class will disappear too actually.
I'll leave this issue open to collect feedback from others, but my personal take on decorators has been a mixture of
from worktop.
To be clear, I'm not interested in the proposed example snippet (or plugins), as that can be done w/o a decorator:
const API = new Router;
API.setSeveralHeaders = function (res, [header, value] = []) {
res.setHeader('foo','bar')
res.setHeader('biz','baz')
res.setHeader('wing','bird')
if (header && value) {
res.setHeader(header, value)
}
};
I also think this particular snippet could just be replaced with the Router.prepare
hook, if need be.
In any event, a core motive for worktop is to do as little runtime work as possible. That should be every framework's goal -- but it's especially true here given that there's a CPU limit. This is why plugins (in the Fastify sense) aren't going to be considered either... it's runtime code that builds up a state only to be thrown away immediately after. All it really does is eat away at that CPU budget. And finally, on this point, it's why worktop offers tree-shakable submodules. Functions are cheap & easily composed. Because you have to involve a bundle-step with worktop (intentional, no way around this), all your methods/utilities should be set up this way.
The decorator API I was considering was something like this:
@GET('/hello/:name')
const list: Handler = async (req, res) => {
// I can skip assigning this to Router
res.end(`hello ${req.params.name}`);
}
So, I think I'll actually close this issue to avoid the confusion. I'll open another to gather feedback about ^this line of thinking for decorators.
What do you think?
from worktop.
Will close this for now. Only recently discovered that decorators are meant to be with/on classes only
Relevant Proposal: https://github.com/wycats/javascript-decorators
Worst case scenario – I implement my idea via typedocs or comments... but maybe there's something else can wiggle together.
from worktop.
Related Issues (20)
- Using Worktop in a Pages website HOT 3
- Use Sveltekit and worktop together? HOT 2
- How to set multiple cookies? HOT 2
- Worktop Middlewares Example HOT 4
- Durable Objects example HOT 2
- The example of timing requests might be misleading HOT 1
- Using official Cloudflare types HOT 4
- Can I use Worktop with Fastly Compute@Edge? HOT 1
- Is it going to be official by cloudflare?
- Cache API and KV: Concerns/Questions/Usage HOT 1
- How to access `.env` with Wrangler 2 HOT 2
- Provide a "test" module HOT 4
- Serving HTML files HOT 6
- How to use with cron / scheduled event ? HOT 2
- Is `worktop@next` safe to use in production? HOT 2
- Add generic typing for Router.add handler
- The uploaded script has no registered event handlers. [API code: 10068] HOT 1
- Add sub-routers HOT 2
- Node 16+ ESM TypeScript error HOT 1
- `isCacheable` allowed cache by default if the `cache-control` header is empty may leading to a security flaw in ssg content HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from worktop.