Computed properties on computed properties


#1

I’m getting some funny behavior using computed properties. I have extracted the relevant parts from the application in this JS bin with some additional debugging:

The general gist is that the isCase and isNotCase do not consistently report their values correctly. So what those two computed properties.

Steps to reproduce:

  1. Click [values] - you should see, “true false” - this is correct
  2. Type y101 into the input box
  3. Click [values] - you should see, “false true” - this is correct
  4. Click [clear] - you will see “false false” - not correct
  5. click [values] - you will see “false false” - not correct

Just trying to understand why isCase (dependent on isNotCase) is not updating properly. You can step through it and see that when it recomputes isCase, it asks isNotCase for its value. isNotCase asks isVolume/isWeight for their computed values, however they do not return the correct value. Thus this incorrectly cached on isCase.

Does this have something to do with the observer? Or the fact that I’m using computed properties on top of computed properties? Is this the desired result?


#2

What’s more crazy… make isWeight return true:

  1. Click [values] - you should see, “true false” - this is correct
  2. Type x101 into the input box
  3. Click [values] - you should see, “false true” - this is correct
  4. Click [clear] - you will see “true false” - not correct
  5. click [values] - you will see “true false” - not correct

And you get the correct result… I’m at a loss.