Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Throw when accessing non-draftables in strict mode#715

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Gelio wants to merge5 commits intoimmerjs:main
base:main
Choose a base branch
Loading
fromGelio:strict-mode-for-non-draftables

Conversation

@Gelio
Copy link
Contributor

@GelioGelio commentedDec 3, 2020
edited
Loading

This MR attempts to implement the idea from#686

It adds astrictMode (false by default, enabled bysetStrictMode or passingstrictMode inImmer constructor) that makes it so that accessing non-draftable properties will throw an error, unless the access is made in anunsafe callback.

Fixes#686

Example

classFoo{}setStrictMode(true)produce({instance:newFoo()},draft=>{unsafe(()=>{draft.instance.abc=1;// works fine in unsafe});console.log(draft.instance);// will throw, because access not wrapped in unsafe});

See the tests for more examples

Limitations

I tried to make it as compliant with existing functionalities as possible. I was not able to make it fully ES5-compliant. There are a few tests that fail when strict mode is enabled inbase.js tests.

I do not have enough expertise to fully fix them. Suggestions are welcome

zroug reacted with thumbs up emoji
In strict mode, accessing a non-draftable property will throwOne can use the unsafe function to perform such operationsFixesimmerjs#686
@codesandbox-ci
Copy link

codesandbox-cibot commentedDec 3, 2020
edited
Loading

This pull request is automatically built and testable inCodeSandbox.

To see build info of the built libraries, clickhere or the icon next to each commit SHA.

Latest deployment of this branch, based on commitc60c592:

SandboxSource
Immer sandboxConfiguration

@mweststrate
Copy link
Collaborator

Really awesome! Thanks for doing this :). Looks really promising, just up front a notif that it will probably take me a while to review 😅

Gelio reacted with thumbs up emoji

@Gelio
Copy link
ContributorAuthor

@mweststrate I'm glad you like it! Take your time to review it

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Idea: forbid grabbing non draftables in strict mode

2 participants

@Gelio@mweststrate

[8]ページ先頭

©2009-2025 Movatter.jp