🏠 back to Observable

I think I'm doing mutable wrong

On a mousepress the code checks of the audioContext is defined (not null) and defines the audioContext
But it seems to be doing the inverse of the if condition

Is this because of something with mutable that I don’t fully get as Matt’s code works fine on glitch.

    if (!audioContext) {
      const AudioContext = window.AudioContext || window.webkitAudioContext;
      mutable audioContext = new AudioContext();  
1 Like

You need to use the mutable keyword at read time as well, otherwise the changing in the value causes the cell to reevaluate because of the read dependency.

if (!mutable audioContext) {
      const AudioContext = window.AudioContext || window.webkitAudioContext;
      mutable audioContext = new AudioContext(); 

Every use of audioContext needs prefixing with mutable (there are lots of uses lower down in the cell too)

I think this is nearly it Comparing Frontend masters Web-Audio by Matt DesLauriers to Frontend masters Web-Audio by Matt DesLauriers / Observable

2 Likes

Thanks, I get it now, I needed to add mutable to all the mutable values used.