Mutable value that is not observed?

Hi,

I would like to have a shared mutable state (say, a number) which I modify periodically (once per second).

However, the mutator function is currently executed automatically, because it depends on the shared value being mutated. What is the recommended way of doing this?

I am trying:

mutable value = 0;

function mutate() { mutable value = value+1; }

loop = {
  while (1) {
    mutate();
    yield Promises.delay(1000);
  }
}

…this loops as fast as possible :frowning:

Try:

function mutate() {
  mutable value = mutable value + 1;
}
1 Like

Thanks, @mbostock! I obviously missed that when reading https://beta.observablehq.com/@jashkenas/introduction-to-mutable-state (it was only mentioned somewhere inside a longer paragraph, albeit being kinda crucial for understanding the mutable keyword).