Chapter 9. Expanding existing Rx apps

 

In this chapter

  • Expanding an existing Rx app to have new features
  • Persisting and loading application state
  • Moving parts of a view model logic into a dedicated model

Working with existing reactive code

One of the advantages of Rx is that adding new functionality to an application is relatively straightforward if the code is structured properly. What you need to do is to carefully think about what you want to change and then reshape the graph accordingly.

In this chapter, you’ll take a piece of code you already wrote and identify the points where your new goals diverge from the old ones.

You’ll be exploring how reactive programming makes the application modular—the chain is just a combination of independent functions—and how to utilize the existing modules.

Starting from tic-tac-toe

You’ll start from a working game of tic-tac-toe, which you already saw in the preceding chapter. Don’t worry if you don’t remember the details, because you’ll revise the implementation before you start applying changes.

This is how the game you already have looks:

In this simple game, the players in turn insert either a cross or a circle. The player who gets three markers in a line wins.

The game of Connect Four

Let’s imagine a real-life scenario: a product owner in their great wisdom has decided that a simple tic-tac-toe game doesn’t cut it in the market anymore. What the cool kids are raving about these days is instead the game Connect Four.

Updating grid size and assets

Checking for valid moves

Coffee break

Saving and loading the game

Creating the model

Sharing the model

Loaded games activity

PersistedGameStore

Saving games

Loading games

Summary