Loading a questionnaire
This section illustrates how the data flows within Pogues. For this, it looks at what happens when a user selects a questionnaire.

When a user selects a questionnaire from the questionnaire list, there are many elementary steps to process, from sending the request to updating the UI. Here is a global picture:
- The application shows the
QuestionnairePickercomponent. - The user selects a questionnaire in the questionnaire list.
- The
switchQuestionnaireaction creator is called. - The
SWITCH_TO_QUESTIONNAIREaction is dispatched. It contains the questionnaire id in its payload. - The switchToQuestionnaire handler from the
appStatereducer updates theviewentry and set it toQUESTIONNAIRE. - The application re-renders.
- When rendering the main
PoguesAppcomponent, theviewentry is checked, and theQuestionnaireContainercomponent is rendered, in place of the previousQuestionnairePickercomponent. - In its
componentWillMountmethod, the loadQuestionnaireIfNeeded function is called. It takes the questionnaire id as an argument. - Assuming the questionnaire has not been already loaded, the
loadQuestionnaireaction creator is called. - The component renders a spinner to indicate that the questionnaire is loading.
- The
LOAD_QUESTIONNAIREaction will be dispatched, with the questionnaire id in its payload. - The getQuestionnaire function is called. The browser tries to fetch the given resource and returns a Promise.
. The fetch call succeeds and the Promise resolves to a
JSONrepresentation of the questionnaire. - The
thenhandler in the action creators file is executed. - It calls the toSate function and dispatches the
LOAD_QUESTIONNAIRE_SUCCESSaction with the result of this function in its payload. - The
LOAD_QUESTIONNAIRE_SUCCESSis processed by many reducers to update the application state: to add an entry in thequestionnaires-by-idreducer, to add multiple entries in thecomponents-by-idreducer (one for each sequence and each question in the questionnaire), to add multiple entries in thecode-by-idreducer (one for each code in every code list in the questionnaire)... - The application re renders. The questionnaire content is now visible.
