proposal-decorators icon indicating copy to clipboard operation
proposal-decorators copied to clipboard

Timeline / proposal for extensions?

Open matthew-dean opened this issue 1 year ago • 9 comments

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?

matthew-dean avatar Apr 10 '23 19:04 matthew-dean

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.

pzuraq avatar Apr 10 '23 19:04 pzuraq

@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.

matthew-dean avatar Apr 10 '23 21:04 matthew-dean

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

ljharb avatar Apr 10 '23 21:04 ljharb

@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.

matthew-dean avatar Apr 11 '23 04:04 matthew-dean

@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?

pzuraq avatar Apr 12 '23 12:04 pzuraq

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

justinfagnani avatar Apr 12 '23 14:04 justinfagnani

@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.

pzuraq avatar Apr 12 '23 15:04 pzuraq

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.

errorx666 avatar Apr 30 '24 15:04 errorx666

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.

Aworldc avatar Jul 18 '24 09:07 Aworldc