We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hello!
Is there a way to avoid mutation of the object that is not a part of the draft? (except deepCopy)
const defaultPart = { y: 1, }; const state = { x: undefined }; const newState = create(state, draftState => { stateDraft.x ??= defaultPart; stateDraft.x.y = 2; // mutates original object }) console.log(defaultPart.y) // 2
I tried to create draft inside but it doesn't finalize
create
... const newState = create(state, draftState => { stateDraft.x ??= create(defaultPart)[0]; stateDraft.x.y = 2; }) console.log(newState.x) // Proxy(Object) { ... }
The text was updated successfully, but these errors were encountered:
hi @prodderman , Mutative does not support finalizing drafts across multiple scopes draft.
Perhaps you can use it like this,
const defaultPart = { y: 1, }; const state = { x: undefined, }; const newState = create(state, (draftState) => { const [subDraft, finalize] = create(defaultPart); subDraft.y = 2; const state = finalize(); draftState.x ??= state; }); console.log(newState.x); // { y: 2 } console.log(defaultPart.y); // 1
Sorry, something went wrong.
You can also use it like this.
const defaultPart = { y: 1, }; const state = { x: undefined, }; let [stateDraft, finalize] = create(state); stateDraft.x ??= defaultPart; [stateDraft, finalize] = create(finalize()); stateDraft.x.y = 2; const newState = finalize(); console.log(newState.x); // { y: 2 } console.log(defaultPart.y); // 1
You must ensure that the correspondence between the immutable tree and the draft is maintained.
No branches or pull requests
Hello!
Is there a way to avoid mutation of the object that is not a part of the draft? (except deepCopy)
I tried to
create
draft inside but it doesn't finalizeThe text was updated successfully, but these errors were encountered: