Instructor: Immer doesn't just simplify producing the next immutable state from the current state. It does a few things more. We're going to refer to our original implementation of toggle reservation.
Here, we have a test, in which we tried to change the reservation of the immutable state, which shouldn't be allowed because that makes it, by definition, mutable, not immutable. What we see is that this is possible. This doesn't trail any exception.
After this happens somewhere in your code base, these are reactions, which are really hard to track down. Secondly, there's another limitation. If we reserve an already reserved GIF, if you look at its implementation, that is still going to produce a new GIF, although it will have to say, "Reference to the same person," which is a bit shame. It means that for example, the component would still be re-rendering if we were able to press a button.
Let's capture that in a unit test as well. First, we check if the GIF that we have in a new state is exactly deeply equal to the previous states, which is the case. It's the object has the same shape.
However, if you're wondering, is it the same object still? Then we see that that's assertion fails. It's not the same GIF anymore. It's not the same object, even though we didn't change it in any way.
If it's not the same object, that also means that it's not the same GIFs collection anymore, that it's not the same state anymore. This is the real culprit. If the initial state is not the next state anymore, it means that on a lot of levels our inaudible we could apply otherwise, aren't applies anymore.
Let's return to our Immer base implementation, save it. Now, we see that out tests are passing. That's this modification actually draws an exception. It also means that every try to reserve more additional GIFs, nothing changes and we literally end up with the very same state as we started with.
These features are made possible by the fact that Immer behaves like our secretary. Our secretary can do a lot of processing such as freezing, such as checking everywhere truly changes...