tc39 / proposal-decorators

Decorators for ES6 classes
https://arai-a.github.io/ecma262-compare/?pr=2417
2.76k stars 105 forks source link

Timeline / proposal for extensions? #506

Open matthew-dean opened 1 year ago

matthew-dean commented 1 year ago

This repo has a lot of really great & valuable extensions that could limit boilerplate in a lot of userland reactive libraries (specifically / let & const decorators).

Is there a separate proposal that tracks those?

pzuraq commented 1 year ago

Parameter decorators are currently in stage 1, being explored here: https://github.com/tc39/proposal-class-method-parameter-decorators

Function decorators are the other major candidate that seems to have enough momentum that they could be included in the language at some point. let/const decorators were discussed before in the plenary briefly, but there was not much appetite for them. We would basically be adding a new getter/setter mechanism to scopes in the language, which is a huge amount of complexity to add, and would make many types of optimizations very difficult.

Personally I'm committed to seeing this proposal and the metadata proposal through the process, and I may try to help with Function decorators after that (given I have the time and energy), but I can't say which, if any, of the proposed extensions will be pursued beyond that.

matthew-dean commented 1 year ago

@pzuraq I think one frustrating thing as a developer is that, had the with keyword not been explicitly forbidden in strict mode, and had ES6 modules not extended strict mode, then reactive variables would have been possible using with + a Proxy object today, without any language additions.

Like, I get that with could be a possible footgun, but it's frustrating that JavaScript used to have features that would have allowed getters / setters on plain variables, and no longer does. I'm just hoping this feature comes back to JavaScript again in the future in a cleaner way.

ljharb commented 1 year ago

"Reactive variables" are something that nonzero people consider to be a footgun, myself included.

matthew-dean commented 1 year ago

@ljharb 🤷‍♂️ Possibly. But it makes UI state updates trivially easy. In the old days, you had to track each and every side effect, and patch manually, or just track nothing and destructively patch everything. And without operator overloading in JavaScript, at least allowing getter / setter on simple assignment / reference would simplify so much real-world code.

pzuraq commented 1 year ago

@matthew-dean doesn’t that just mean users have to define a class or object with accessors to intercept access to reactive values? Is the goal to enable something like the reactivity in Svelte’s reactive statements?

justinfagnani commented 1 year ago

Svelte reactivity isn't implementable even with reactive variables because Svelte also treats a module as an instantiable thing, like a class.

pzuraq commented 1 year ago

@justinfagnani Yeah I was going to bring that up, I just am trying to understand the use cases before digging into potential issues, wanna make sure I’m not missing anything.

errorx666 commented 6 months ago

I definitely want to see function decorators as soon as possible. I tend to favor less object-oriented design patterns in JS.

Object literal and property decorators also interest me, as I use those more than classes.

Aworldc commented 4 months ago

yes, i also think function decorators would be the most useful.

i also think that const decorators would also be extremely useful, as you can wrap any value into any other value in an extremely simple way.