Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: support return values in the draft function #3

Closed
unadlib opened this issue Jan 11, 2023 · 1 comment
Closed

Proposal: support return values in the draft function #3

unadlib opened this issue Jan 11, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@unadlib
Copy link
Owner

unadlib commented Jan 11, 2023

reduxjs/redux-toolkit#3074

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.

@unadlib
Copy link
Owner Author

unadlib commented Jan 14, 2023

Suggestion from reduxjs/redux-toolkit#3074 (comment)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant