Chapter 3. Models and Data
One of the challenges with moving state to the client side is data management. Traditionally, you could fetch data directly from the database during the page request, interoperating the result directly into the page. However, data management in stateful JavaScript applications is a completely different process. Thereâs no request/response model, and you donât have access to server-side variables. Instead, data is fetched remotely and stored temporarily on the client side.
Although making this transition can be a hassle, there are a few advantages. For example, client-side data access is practically instantaneous, as youâre just fetching it from memory. This can make a real difference to your applicationâs interface; any interaction with the application gives immediate feedback, often dramatically improving the userâs experience.
How you architect data storage on the client side requires some thought. This is an area riddled with pitfalls and potential traps, often tripping up less-experienced developersâespecially as their applications get larger. In this chapter, weâll cover how best to make that transition, and Iâll give you some recommended patterns and practices.
MVC and Namespacing
Ensuring that thereâs a clear separation between your applicationâs views, state, and data is crucial to keeping its architecture uncluttered and sustainable. With the MVC pattern, data management happens in models (the âMâ of MVC). Models should be ...
Get JavaScript Web Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.