Skip to content

get/set/get should be supported#21225

Description

@NullVoxPopuli

馃悶 Describe the Bug

get/set/get should work -- this is also known as lazy initialization, and is a very nice user convenience -- and I don't think we need we to error in this case and can instead error after a get after the set.

馃敩 Minimal Reproduction

Here is get/set/get working in solidjs: https://playground.solidjs.com/anonymous/fa7ab1b1-cbab-4a5a-b838-89d1b26c6140

Here is the repro of the error:
https://limber.glimdown.com/edit?c=JYWwDg9gTgLgBAYQuCA7Apq%2BAzKy4DkAAgOYA2oI6UA9AMbKQZYEDcAUKJLHAN5wwoAQzoBrdABM4AXzi58xcpWo1BI0cFQk2nFD35oZcvCEJF0IAEYqQECcGzBqO9ugAe3eBPTYhAVzJ4OjIhAGdQuAAJdDIyCAB1aDIpdxhMCQikFGZ4XnY4OCI1MUk4Bj8sDny4EnQYAGU6gHE6uABeOAAKAEp2gD4%2BaoKyVrp2gQALYFCAOnLK9iGytFCIEZm4kk7%2BMelujgKCvMPDhy6AQjpemCnZ%2BfgOgCYDw%2Bkqk4ZUVfXNzpvpuYQCowfZLKB1PxQVCTAH3F5vRYFTR0cFULDjHr9GF3IHogDUHQAjO84AAeNLgEJpPpLUlgPoATSBcAmQgAbugyhQSlIbpzLH4YDBDLxeH9bjNag1mnVutJZDBQOhZqSaPTEYdSQKhYYYABPMDoNoAIm1wtQxr4vEMxuCwDElv%2Bs2RqMwMHlfQQ3NEqrNaBpBVVFLAVPQNOk7CAA&format=gjs

Assertion Failed: You attempted to update `count` on `HelloWorld`, but it had already been used previously in the same computation.  Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.

`count` was first used:

- While rendering:
  {ROOT}
    (result of a `unknown` helper)
      (result of a `(helper function getSetGet)` helper)

Stack trace for the update: (see console)

code:

import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { on } from '@ember/modifier';

export default class HelloWorld extends Component {
  @tracked count;

  getSetGet = () => {
    let c = this.count;

    console.log({ c });
    {
      if (!c) this.count = 2;
    };

    console.log(this.count);
    return this.count;
  };

  increment = () => this.count += 1;

  <template>
    <p>You have clicked the button {{(this.getSetGet)}} times.</p>

    <button type="button" {{on "click" this.increment}}>Click</button>
  </template>
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions