I can't quite wrap my head around this. Why did the React and Next team chose to rely on JavaScript directives instead of decorators?
Decorators are widely used by a plethora of frameworks like Angular or Nest.js. They're widely used between different languages and mostly standardized. Directives are a JS thing only. They're not even widely used. Before React team adopted it we only used it for "use strict" and most of us didn't even see that since it was being added by a bundler.
We could also eliminate Next.js' magic string exports and pass them to options of the decorators.
I guess decorators are still in stage 3 and directives have been a part of the languages since ES2015. So that might be the cause?
Here are some examples of the API usage I was thinking of for decorators vs directives.
Directive:
async function actionFoo() {
"use server";
...
}
Decorator:
@ServerAction
async function actionFoo() {
...
}
Directive:
"use cache";
export const dynamic = 'force-dynamic';
export async function HomePage() {
...
}
Decorator:
@Page({ cache: true, dynamic: "force-dynamic" })
export async function HomePage() {
...
}