>> Richard Feldman: So by doing this, we can prevent as many of these sort of state synchronization bugs as possible, by sort of thinking in terms of who's the cache, who's the source of truth?
[00:01:48] And we want to have as few sources of truth as possible, and have the hierarchy be the one that is the most reliable is sort of at the top, and everybody else is just caching that at best. So to recap, we started off by talking about impossible states that we can end up in.
[00:02:07] Multiple sources of truth is one possible way we can do that. We looked at the tab var, where we had each of the tabs potentially thinking that they were the one that was active. And when we shift that to say there's only source of truth, we model each of these tabs as a different variance in a custom type, and all we can have is one source of truth for which one is active.
[00:02:27] That prevented that impossible state from happening, which actually did come up in practice before. I talked about derived data, and how when we start off with something that's like a timestamp in the database, it goes through a number of transformations before it makes it all the way to being rendered for the user.
[00:02:41] In a lot of cases, we can't avoid caching that in the model, which is fair enough. But if we can, it's best to do that derived data in the view, not storing it in the model where it can potentially end up as a competing source of truth. We talked about authentication and how, again, ultimately the source of truth is on the server.
[00:02:58] And if we disagree with the server, we're out of luck. So we're gonna cache stuff for performance reasons, so that we don't have to have the users enter their credentials every single time they wanna do something. But we're gonna be aware that those things are caches. And we're gonna take as many steps as we can to prevent those caches from getting stale by doing things like every time local storage updates, updating the model, and not ever changing the session in the model through any other means other than refreshing that cache.
[00:03:37] Because the consequence of having competing sources of truth is much more severe than the minor inconvenience of having to ask it for its state on a regular basis.