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

fix(core): improve DeepResolveType type #324

Merged
merged 3 commits into from
Jan 13, 2022
Merged

fix(core): improve DeepResolveType type #324

merged 3 commits into from
Jan 13, 2022

Conversation

BernieCr
Copy link
Contributor

I think it would be a nice addition to declare snapshots as immutable on Typescript level. This makes it easier for users to notice that they are only supposed to modify the store, not the snapshot.

I also took the liberty to rename the type to Snapshot, it's probably better than DeepResolveTypeReadonly.
Awesome library by the way!

@vercel
Copy link

vercel bot commented Jan 13, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pmndrs/valtio/9GwJNSE846Aw5KhMB3hac6GYE8oP
✅ Preview: https://valtio-git-fork-johnnynomad-main-pmndrs.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 13, 2022

This pull request is automatically built and testable in CodeSandbox.

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

Latest deployment of this branch, based on commit 3fbbeb7:

Sandbox Source
React Configuration
React Typescript Configuration
React Browserify Configuration
React Snowpack Configuration
React Parcel Configuration

@BernieCr BernieCr changed the title Feat: declare snapshots as immutable in Typescript feat: declare snapshots as immutable in Typescript Jan 13, 2022
Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion. Just curious, was the previous typing somehow causing a trouble?

src/vanilla.ts Outdated Show resolved Hide resolved
src/vanilla.ts Outdated Show resolved Hide resolved
src/vanilla.ts Outdated Show resolved Hide resolved
src/vanilla.ts Outdated Show resolved Hide resolved
@BernieCr
Copy link
Contributor Author

Wow, that was a fast code review!

Just curious, was the previous typing somehow causing a trouble?

No, not at all. I am a freelance developer and am looking for state management libraries I could potentially recommend in future projects.
This is easier if other developers that are not familiar with this library and its concepts are automatically prevented from making common mistakes.
I personally played around with this library quite a bit now and did some reading, and know I understand the reason for the creating snapshots and why you can't modify them, but it took some time.

src/vanilla.ts Outdated
}
: T
: Readonly<T>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: Readonly<T>
: T

Looks like we don't need this.
Check this out: https://tsplay.dev/NlxQXN
Or, please let us know the case it might break.

Copy link
Contributor Author

@BernieCr BernieCr Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah that's true, I actually hadn't studied the Readonly<> type in detail.
While checking this I noticed that the Map, Setand Date types aren't immutable with the current implementation. Do you think we should cover those cases as well, or would that be overkill?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are indeed not immutable. So, it's correct. Actually, it's not deterministic. With #321, we could technically change the behavior at runtime. So, we can't provide 100% static type anyway.

@dai-shi dai-shi changed the title feat: declare snapshots as immutable in Typescript fix(vanilla): improve DeepResolveType type Jan 13, 2022
@dai-shi dai-shi merged commit a983b8b into pmndrs:main Jan 13, 2022
@dai-shi dai-shi changed the title fix(vanilla): improve DeepResolveType type fix(core): improve DeepResolveType type Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants