I have inherited an application written using Knockout for the UI and I am curious as to what the effect is of having multiple subscriptions against a single observable property?
I have an observable that has 2 subscriptions. By logging to the console I can see that both subscriptions get fired, one after the other.
Using the following example: (this is very stripped down for brevity in the full code there is lots of logic, some of which is duplicated)
self.VisitDate = ko.observable();
self.VisitDate.subscribe(function (newValue) {
self.ListItemRemoved(removed);
});
self.VisitDate.subscribe(function (newValue) {
self.Basket.VisitDate(newValue);
});
I was thinking that I should see some sort of error, because of the multiple subscriptions, but everything appears to work fine but I cannot find any clear explanation of why this is OK to do?
I am just trying to find out the following:
Is it normal and acceptable to have multiple subscriptions to a single observable? Is there any underlying impact on doing this i.e. race conditions maybe? Is there ever really any need to have multiple subscriptions to achieve something that cannot be achieved in a single subscription?
I appreciate this may be a little shy in detail but I am really just trying to get an understanding of how knockout is doing things under the covers to see whether I should be looking to refactor this code or not.