I have the following:
sidebarCardVm.showCreateButton = ko.computed(function () {
return
(sidebarItemType == "Test") ||
(sidebarItemType == "Test2" && self.selectedItem() != null); // when selectedItem() changes, I expect this to fire. It does not.
});
I expect a change of selectedItem to trigger this:
self.selectedItem = ko.computed(function () {
var matchingCard = getSelectedCard("Item")
if (matchingCard != null && matchingCard.selectedItem() != null)
return matchingCard.selectedItem();
return null;
});
But it does not. I see self.selectedItem update, but showCreateButton doesn't follow suit. Why is this?
Computeds are very smart in determining their dependencies. For example:
Because when
exitEarlyis stilltruethe code never reaches the point where it callsmyObs, no subscription is created. Only once it gets to the second part of the||, we'll start triggering updates for new values ofmyObs.Therefore, this piece of code:
by definition, can not create a subscription to
selectedItem.Whenever
sideBarItemType === "Test", it will return early and not callselectedItem.