Defining the sharing data requirement
Let’s assume that we have four components – C1, C2, C3, and C4 – that do not have any relationship with each other, and there is information – DATA – shared between those components:
Figure 7.1 – Shared data between components
The components can update and consume DATA at the same time. But at any time during the process, the components should be able to access the last value of DATA.
Now, let’s make that explanation clearer with a more concrete example.
In our recipe application, when the user clicks on one recipe, it gets selected, but we want all components to have access to the last selected recipe by the user. In that case, the selected recipe represents our shared data.
One of the components that will need access to the selected recipe is the RecipeDetailsComponent
component, as it will display the details of the selected recipe.
Without further ado...