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

Idea: forbid grabbing non draftables in strict mode #686

Open
mweststrate opened this issue Oct 21, 2020 · 1 comment · May be fixed by #715
Open

Idea: forbid grabbing non draftables in strict mode #686

mweststrate opened this issue Oct 21, 2020 · 1 comment · May be fixed by #715

Comments

@mweststrate
Copy link
Collaborator

🚀 Feature Proposal

See #674 and many other issues where people are surprised that Immer by default totally ignores their class instances.
The idea is that if a field contains a non-draftable object, it becomes unreadable. E.g.: produce(state, draft => { draft.buffer; }) would throw. To still use the buffer inside a draft, a explicit signal needs to be given, e.g. produce(state, draft => { mutableRef(draft.buffer).push(17); ).

Not sure about the name: mutableRef, unsafe could all work. Or maybe we could even reuse the existing original method for this purpose, although that might be confusing.

For easy backward compatibility an option enableStrictMode(boolean) could be used, by default off in the current version, and enabled in the next major.

Can this be solved in user-land code?

No

Gelio added a commit to Gelio/immer that referenced this issue Dec 3, 2020
In strict mode, accessing a non-draftable property will throw
One can use the unsafe function to perform such operations

Fixes immerjs#686
Gelio added a commit to Gelio/immer that referenced this issue Dec 3, 2020
In strict mode, accessing a non-draftable property will throw
One can use the unsafe function to perform such operations

Fixes immerjs#686
@Gelio Gelio linked a pull request Dec 3, 2020 that will close this issue
@Gelio
Copy link
Contributor

Gelio commented Dec 3, 2020

I tried to take a stab at implementing this in #715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants