You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the object is a Map, calls to the map.set() method triggers the callback with 3/4 incorrect arguments (path, value, previousValue):
const _state = new Map();
const state = onChange(_state, (path, value, previousValue, applyData) => {
console.log(`Changed ${path} from ${JSON.stringify(previousValue)} to ${JSON.stringify(value)}`);
});
state.set("a", "hello, world");
Produces the following output: "Changed from {} to {}".
I can achieve part of the intended behaviour with applyData.args[0] for the path and applyData.args[1] for the value, but this seems like it is pretty ripe for unforeseen errors.
Any thoughts?
The text was updated successfully, but these errors were encountered:
First, JSON.stringify on a map will always produce "{}", no matter the contents. I have tests verifying that value and previous value are correct. In your console.log, if you instead used value.get('a') you would see the 'hello, world' on value.
Second, the path. Since you can't access the contents of a map with dot syntax, in your example _state.a is undefined, it was determined to just show the path to the map, not within it. Then you can extrapolate from the value, previousValue, and/or applyData what changed. In this case the applyData tells you exactly what changed.
Version 3.0.2
When the object is a Map, calls to the
map.set()
method triggers the callback with 3/4 incorrect arguments (path, value, previousValue):Produces the following output: "Changed from {} to {}".
I can achieve part of the intended behaviour with
applyData.args[0]
for the path andapplyData.args[1]
for the value, but this seems like it is pretty ripe for unforeseen errors.Any thoughts?
The text was updated successfully, but these errors were encountered: