I can subscribe to a store like this:
count.subscribe(value => {
count_value = value;
});
but when we want to unsubscribe we will put the previous subscribe code into a new variable (becomes a function expression) and run it only when the component is destroyed (onDestroy)
const unsubscribe = count.subscribe(value => {
count_value = value;
});
onDestroy(unsubscribe);
the question is, how about just putting the previous function into a new variable called unsubscribe. can perform the unsubscribe function to the store. I mean we don't even change the subscribe code at all for the unsubscribe implementation, all we do is put it in a new variable so it becomes a function expression and only call it via onDestroy, then how can it magically unsubscribe? how does it actually work?