Part 3 Improving the framework

 

The groundwork has been laid, and your framework can successfully render a website based on a virtual DOM representation while keeping it in sync as users interact with it. But let’s be honest: having the entire application’s state confined to a single object managed by the application isn’t the most practical approach. Wouldn’t it be more efficient if each component could take charge of its own piece of the state, focusing solely on the view it oversees?

In this final part of the book, you’ll delve into the world of stateful components—components that autonomously manage their own state and lifecycles. They are responsible exclusively for the view they oversee and can be combined to create more intricate views. This enhancement empowers the application to bypass the reconciliation algorithm for every change, updating only the components that are affected by the modification.

You’ll explore how stateful components can incorporate other components within their view and establish communication among them. You’ll also implement a scheduler that enables the asynchronous execution of component lifecycle hooks—a potent feature that a robust framework should offer. Last but not least, you’ll master the art of performing thorough unit testing on components defined within your framework, even when they involve asynchronous behavior.