A common bane of web development is writing routines to parse data that is returned from the server into a conveniently accessible format for the core application logic. While many good routines have been developed to parse common response types such as comma-separated values (CSV) and JSON, a lot of boilerplate is still involved in wiring it all up, issuing updates back to the server, potentially maintaining synchronicity between the local store and the server, and so forth. This chapter introduces Dojo's data APIs, which provide a uniform interface for handling data sources—regardless of where they're located, how they're accessed at the transport level, and what their format may be.
The toolkit's machinery for managing data sources isn't exactly rocket science, but it does require shifting the paradigm ever so slightly, in that it requires that data can be treated as a local resource that is accessed via a uniform API. Traditional approaches have typically entailed treating data as a remote resource, which necessarily entails acquiring boilerplate to retrieve it, writing updates to the server, maintaining synchronicity with the server, and handling variable formats. One of the central issues, historically speaking, is that the wheel was reinvented far too many times and virtually every application used its own brittle approach to managing the burden of handling data.
Dojo gives a set of APIs via the dojo.data
module that provide a standardized
means for interacting with arbitrary data sources, shown in Figure 9-1. This allows application
programmers to escape entanglement with retrieving, parsing, and
managing it. The dojo.data
API
provides a standardized manner for interacting with data whether it's
local or remote, which is a tremendous boon when it comes time to deal
with larger and larger data sets as an application scales. Best of
all, once you've implemented an interface for a specific data format,
it becomes an off-the-shelf resource that you can reuse and distribute
at will. Generally speaking, these kinds of off-the-shelf resources
allow application developers to be more productive by allowing them to
focus on far more interesting tasks at hand than I/O
management.
Get Dojo: The Definitive Guide 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.