vendredi 24 juin 2016

ember js - value returned from computed property looks cached

I am having this weird issue while returning an array from a computed property. I got to know the problem exactly (as below), but not sure about solution. Have created a twiddle for demo purpose to explain.

Case 1: http://ift.tt/28SmCgT

Steps:

a) Check the first checkbox and if we see the value of "arr" in console, the "newprop" property will be added to each object in "arr"

b) Un check the same checkbox, see the console, the same "arr" is returned with that "newprop" still there. But I was assuming, it wouldn't have been there, as there is a check for that in if condition.

So, after little troubleshooting, I came up with this identical next twiddle.

Case 2: http://ift.tt/28UPlEG

perform the same steps and we see that this time the "arr" doesn't have "newprop" when the checkbox is unchecked

The only difference between twiddle is that the array (having data/model) in the first one is defined in "getData" itself and in second, its taking it from another computed property "what".

What I am looking for: I need to have case 1 twiddle working, but when the checkbox is unchecked, the "arr" should return the actual original "arr" without the "newprop". Also, need to understand why its happening. The only thing changed is that fetching the data directly inside fn or via another computed property.




Aucun commentaire:

Enregistrer un commentaire