You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's important to understand that a property like todo actually houses two distinct values:
lastSetValue - TheVALUE that was last set like vm.todo = VALUE
getterValue - The value that was last returned by the get function or passed to resolve(). This is the result of reading the property like: vm.todo.
It's important to understand that calling resolve() with a value will not set lastSetValue. Instead, calling resolve() only changes the getterValue.
Lets see how this plays out with an example. The following sets todoId and binds to todo. When todoId changes, a different todo instance can be read:
vm.on("todo",function(){});// logs: re-calculating undefined// ONCE THE PROMISE RESOLVESvm.todo//-> Todo{id:5}vm.todoId=6// logs: re-calculating undefined// ONCE THE PROMISE RESOLVES AGAINvm.todo//-> Todo{id:6}
Now, once todo is set, given the get above, vm.todo's getterValue will match lastSetValue even as todoId changes:
This would create a cycle in the graph of dependencies. It would change the get from a "map" to a "scan/reduce" (in observables speak). map is more simple. Effectively get is mapping the lastSetValue and other values read (ex: this.otherProp) to the resolved getterValue.
If resolve updated the lastSetValue, I would call the argument lastGetterValue. This would be similar to scan/reduce. This is useful for a variety of patterns, but so is map.
I think the following might be a useful addition to our documentation:
The difference between lastSetValue and resolve
Summary:
getters
maintain both a lastSetValue and a getterValue. These are used for different parts of write and read functionality.Getters like the following often confuse people:
It's important to understand that a property like
todo
actually houses two distinct values:VALUE
that was last set likevm.todo = VALUE
get
function or passed toresolve()
. This is the result of reading the property like:vm.todo
.It's important to understand that calling
resolve()
with a value will not setlastSetValue
. Instead, callingresolve()
only changes thegetterValue
.Lets see how this plays out with an example. The following sets
todoId
and binds totodo
. WhentodoId
changes, a different todo instance can be read:Now, once todo is set, given the
get
above,vm.todo
's getterValue will match lastSetValue even astodoId
changes:vm.todo
's__getterValue__ will match __lastSetValue__ even as
todoId` changes, unless lastSetValue is set to false:The text was updated successfully, but these errors were encountered: