react-native-fabric
react-native-fabric copied to clipboard
Answers.logCustom is making objects Immutable
Made a redux middleware logger for this package, and is breaking from modifying the object to be Immutable:
const reduxLogMiddleware = store => next => action => {
// This is the equivalent of Answers.logCustom('name', { ... })
Answers.logCustom(action.type, action);
return next(action);
};
This will throw an error deeper in the application, as action
is modified to become immutable:
Error: You attempted to set the key ... with the value ... on an object that is meant to be immutable and has been frozen.
at throwOnImmutableMutation
which is probably from here react-native/Libraries/BatchedBridge/MessageQueue.js
Is there any way to avoid this without making clones of every logged object? This fixes the problem, but is not ideal:
Answers.logCustom(action.type, Object.create(action));
That would be the solution in this case, this seems more like a redux issue than an issue with this module as all we are doing is sending the object across the bridge.
The only other option would be to clone the object in https://github.com/corymsmith/react-native-fabric/blob/master/Answers.js but may be overkill since it only seems to affect users using redux / immutable.