🏠 back to Observable

Mutable value that is not observed?



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) {
    yield Promises.delay(1000);

…this loops as fast as possible :frowning:



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


Thanks, @mike! 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).