[Proposal] New syntax for lazy getters
Michał Wadas
michalwadas at gmail.com
Tue Jun 12 18:16:09 UTC 2018
Yes, something is getting done about decorators.
https://github.com/tc39/agendas/pull/398
On Tue, Jun 12, 2018 at 4:27 PM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:
> To me decorators are the answer to pretty much everything but for the last
> year I've seen zero progress on what seems to be a forever Stage 2
> proposal: https://github.com/tc39/proposals#stage-2
>
> Is there anything anyone can do to speed up adoption/implementation of
> that proposal?
>
> On Tue, Jun 12, 2018 at 4:24 PM, Augusto Moura <augusto.borgesm at gmail.com>
> wrote:
>
>> I don't think a new keyword is the right path here. For classes lazy
>> fields can easily be implemented via decorators in the last proposal[1]
>> (also, Groovy has previous work implementing a `@Lazy` annotation[2] with
>> AST transformations for the same use case). In code something like:
>> ``` js
>> const lazy = (fieldMetadata) => {
>> // change the field value in descriptor to a lazy factory
>> };
>>
>> class Foo {
>>
>> @lazy bar = slowCalculation();
>>
>> @lazy statements = (() => {
>> if (this.bar > 0) {
>> return fooify();
>> } else {
>> return barify();
>> }
>> }());
>>
>> }
>> ```
>>
>> What it's doesn't cover (and in my opinion should be the focus of a new
>> proposal) is Decorators for literal objects. Something like the code below
>> is yet not proposed:
>>
>> ``` js
>> const foo = {
>> @lazy bar: 3,
>> };
>> ```
>>
>> I didn't made a deep search in ESDiscuss history but I remember this
>> feature being mentioned sometime ago.
>>
>> [1]: https://github.com/tc39/proposal-decorators
>> [2]: http://groovy-lang.org/metaprogramming.html#xform-Lazy
>> --
>> Augusto Moura
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180612/ff8e48da/attachment.html>
More information about the es-discuss
mailing list