I know there are solutions to get the new value of an observable in a subscribe event (after the actual change), but I was wondering if it's possible to access the new value of an observable in a "beforeChange" subscription.
Below is a snippet of the current version of Knockout (3.4.1) raising the beforeChange and afterChange subscription handlers with the old value and the new value respectively:
if (computedObservable.isDifferent(state.latestValue, newValue)) {
if (!state.isSleeping) {
computedObservable["notifySubscribers"](state.latestValue, "beforeChange");
}
state.latestValue = newValue;
if (DEBUG) computedObservable._latestValue = newValue;
if (state.isSleeping) {
computedObservable.updateVersion();
} else if (notifyChange) {
computedObservable["notifySubscribers"](state.latestValue);
}
changed = true;
}
Apparently the newValue is available at "beforeChange" so I guess forking would be an option, but I'd prefer not to.
Is there any other solution to get this new value "beforeChange"?