corymsmith / react-native-fabric

A React Native library for Fabric, Crashlytics and Answers
MIT License
1.31k stars 237 forks source link

Answers.logCustom is making objects Immutable #129

Open braco opened 7 years ago

braco commented 7 years ago

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));
corymsmith commented 6 years ago

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.