This is not a technical question, but I was curious which approach is best suited for such a problem? Although I have this problem in Knockout, I’m sure that the use case will be valid elsewhere.
Suppose that I have signed a two variables simpleObserve1, simpleObserve2so that every time changes their meaning, they call the function resetAllValues().
var simpleObserve1 = ko.observable(0),
simpleObserve2 = ko.observable(0);
var resetAllValues = function resetAllValues() {
{...}
}
simpleObserve1.subscribe(function(){
resetAllValues();
});
simpleObserve2.subscribe(function(){
resetAllValues();
});
simpleObserve1(5);
simpleObserve2(10);
2 questions here.
- When resetAllValues () is called, it changes all signed values to 0, including
simpleObserve1and simpleObserve2. This, in turn, calls resetAllValues()again and again. How can I prevent this from going into an infinite loop? - , ,
resetAllValues() ?
knockout dispose(), , , .