Closed unadlib closed 1 year ago
Suggestion from https://github.com/reduxjs/redux-toolkit/pull/3074#issuecomment-1379334527
Since the user may refer to the draft in the return of a completely new object, I will use the option strict
, which we will suggest the user enable strict
in development mode and disable strict
in production mode. This will ensure safe returns and also keep good performance in the production build.
If the return value is mixed drafts or undefined
, then use safeReturn()
wrapper.
If support return values in the draft function, this would mean that Mutative would need to determine if the value is a draft, and do a deep traversal of non-draft return values, and such an unpredictable return value would waste a considerable amount of performance.
But the community wants mutative to support it. The good thing is that Mutative makes a lot of performance improvements, and it doesn't lose any performance as long as we suggest trying to return the draft itself as much as possible in usage scenarios like Redux's reducer. Even if the returned value is not a draft, it doesn't have significant performance loss and we will have performance benchmarks to track it.