emberjs / emberjs/ember.js

get/set/get should be supported

Open
#21,225 2 comments 1 reaction 0 assignees View on GitHub
Needs Research Proposed Feature
Dominant language
TypeScript
Stars
22.6k
Forks
4.2k
Avg merge
3d 12h
Merged PRs (30d)
15

Description

### 🐞 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:
```gjs
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;


You have clicked the button {{(this.getSetGet)}} times.

Click

}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.