-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
get/set/get should be supported #21225
Copy link
Copy link
Open
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
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>
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels