5 State management and the application’s lifecycle

 

This chapter covers

  • Understanding state management
  • Implementing a state management solution
  • Mapping JavaScript events to commands that change the state
  • Updating the state using reducer functions
  • Re-rendering the view when the state changes

Some time ago, I went to the coast in the south of Spain, to a small village in Cadiz. One restaurant was so popular that it ran out of food quickly; it served a limited quantity of the dishes on the menu. As waiters took orders from customers, they updated a chalkboard with the number of servings the restaurant had left, and when no more of a particular dish was left, they crossed it out. The customers could easily tell what they could order by looking at the chalkboard. But from time to time, due to the workload, a waiter might forget to update the chalkboard, and customers would find out that the dish they’d been waiting in line so long to order was sold out. You can picture the drama. Clearly, it was important for the restaurant to have an updated chalkboard that matched the remaining servings of each dish.

5.1 The state manager

 
 

5.1.1 From JavaScript events to application domain commands

 

5.1.2 The reducer functions

 
 
 

5.1.3 The dispatcher

 
 

5.1.4 Result

 
 

5.2 Assembling the state manager into the framework

 
 

5.2.1 The application instance

 
 
 
 

5.2.2 The application instance’s renderer

 
 

5.2.3 The application instance’s state manager

 
 

5.2.4 Components dispatching commands

 

5.2.5 Unmounting the application

 
 
 

5.2.6 Result

 

Summary

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage