Saving to local storage via Redux middleware
In this section, we’ll update our app to save the current state to local storage, a persistent data store managed by the user’s web browser. We’ll do that by way of Redux middleware.
Each time a statement is executed in the Spec Logo environment, the entire set of parsed tokens will be saved via the browser’s LocalStorage
API. When the user next opens the app, the tokens will be read and replayed through the parser.
The parseTokens function
As a reminder, the parser (in src/parser.js
) has a parseTokens
function. This is the function we’ll call from within our middleware, and in this section, we’ll build tests to assert that we’ve called this function.
We’ll write a new piece of Redux middleware for the task. The middleware will pull out two pieces of the script state: name
and parsedTokens
.
Before we begin, let’s review the browser LocalStorage
API:
window...