Hi,
I’m migrating to the new getter/setter syntax, but I don’t understand why when I call .get('foo')
foo’s get
function is not called. Could somebody explain why? Thanks!
See here for a comparison of old style vs new style.
Hi,
I’m migrating to the new getter/setter syntax, but I don’t understand why when I call .get('foo')
foo’s get
function is not called. Could somebody explain why? Thanks!
See here for a comparison of old style vs new style.
With the new setter syntax you still need to return the new value of the computed property after you have updated it in your set function. http://emberjs.jsbin.com/pacomefobu/1/edit
Ok, fair enough.
Seems a bit weird to make a call to .get, and get
not be called.
The reason why get
isn’t called is because Ember tries to be smart and caches the result (in case your get
function is expensive). So in this case Ember is remembering the return value from the set
and returning that cached values instead of calling get
. If you had called get
before the set
or if you change the value of bar
(thus invalidating foo
’s cache) you would see Ember call the get
function like you would expect.
Ah right, that makes sense
I see where volatile
comes in now.
Thanks!