-
Notifications
You must be signed in to change notification settings - Fork 644
Fix snapshotProcessor.is #1495
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 snapshotProcessor.is #1495
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change itself looks fine, but can you explain why the existing test needed updating? It now changes it's behavior and no longer converts a string to a number.
Also, can you introduce a new test that hit's and confirms the change in this PR?
@mweststrate thank you for the prompt reply, appreciate it. 🙂 The existing test was updated to reflect the change I made in this pull request. Without the change, the test will fail. In addition, the test is still valid for the behavior it was introduced by so I don't think an additional test is needed here. |
Ok, then I don't get your change. The test is a valid case: where a string Your original issue with the code sandbox had a nice test case, where a model instance wasn't properly recognized as being assignable to a snapshot type. So what I would expect to see: the current test to be unchanged (or an explanation why that test was wrong all along). And a new test that demonstrates that model instances are now indeed correctly recognized as instances of that snapshot type. Hope that makes sense! |
Let me try to explain a bit more clearly. The intent of the original test case was to check that The test passed but it was accidental. In the following expectation expect(ProcessedModel.is(processedModel)).toBe(true) we're passing the model instance to So in the step: { ...sn, x: Number(sn.x) }
I changed the implementation of the The implementation was then changed to check if It should not be a breaking change since the only difference is using Hopefully this made it somewhat more clear. 🙂 |
@mweststrate did that clear things up or do you still want me to introduce a separate test case? 🙂 |
Nope, thanks for the explanation and apologies for the late follow up! If you need more changes like this in the future and are interested in maintainer rights, let me know :) It allows you to branch directly on this repo and that is a much more convenient workflow. I'll try to release this today :) |
Released in 3.16.0 |
…cessor.is override This fixes a bug where within `.is` on models with snapshot processors, we validated against the model snapshot, instead of the model node when given a node. This means that two different models with compatible snapshots would not `.is` instances of each other normally, but once a snapshot processor is added, they would. This adds a failing test capturing this case. The PR that introduced this behaviour of validating the snapshot was introduced here: mobxjs#1495, and I think was actually targeting a different use case -- passing *snapshots* to `.is`, not passing instances. The behaviour that PR added was to validate against the __processed__ version of a snapshot if passed a snapshot, which this PR maintains. But, if passed an instance, that PR elected to snapshot it as well, which I don't think is necessary, and breaks the substitutability of snapshot processed instances with their unwrapped counterparts.
…cessor.is override This fixes a bug where within `.is` on models with snapshot processors, we validated against the model snapshot, instead of the model node when given a node. This means that two different models with compatible snapshots would not `.is` instances of each other normally, but once a snapshot processor is added, they would. This adds a failing test capturing this case. The PR that introduced this behaviour of validating the snapshot was introduced here: mobxjs#1495, and I think was actually targeting a different use case -- passing *snapshots* to `.is`, not passing instances. The behaviour that PR added was to validate against the __processed__ version of a snapshot if passed a snapshot, which this PR maintains. But, if passed an instance, that PR elected to snapshot it as well, which I don't think is necessary, and breaks the substitutability of snapshot processed instances with their unwrapped counterparts.
…ocessor.is` override (#2182) * Validate state tree instances instead of snapshots in the SnapshotProcessor.is override This fixes a bug where within `.is` on models with snapshot processors, we validated against the model snapshot, instead of the model node when given a node. This means that two different models with compatible snapshots would not `.is` instances of each other normally, but once a snapshot processor is added, they would. This adds a failing test capturing this case. The PR that introduced this behaviour of validating the snapshot was introduced here: #1495, and I think was actually targeting a different use case -- passing *snapshots* to `.is`, not passing instances. The behaviour that PR added was to validate against the __processed__ version of a snapshot if passed a snapshot, which this PR maintains. But, if passed an instance, that PR elected to snapshot it as well, which I don't think is necessary, and breaks the substitutability of snapshot processed instances with their unwrapped counterparts. * docs: bump JSdocon snapshotProcessor is * docs: one more link for snapshotProcessor * chore: version bump to 7.0.0-pre.1 --------- Co-authored-by: Tyler Scott Williams <tyler@coolsoftware.dev>
No description provided.