Reducers

src/reducers/index.js: Managing the Application State

src/reducers/index.js is responsible for managing the application's state using the Redux library. It defines reducers, which are pure functions that take the current state and an action as input and return a new state based on the action's type and payload. This file ensures that the application's state is updated consistently and predictably in response to user interactions and data updates.

1. Reducer Structure

The file combines multiple reducers into a single root reducer using the combineReducers function from Redux. This allows for a modular and organized approach to state management, where each reducer is responsible for a specific part of the application's state.

1.1. demo Reducer

The demo reducer manages the state related to the SILAS Web demo app, including:

  • keplerGl: Stores the state of the Kepler.gl map, including data, layers, and configuration.
  • cloudProviders: Contains information about the available cloud providers.
  • featureFlags: Defines feature flags that control the availability of certain features.
  • localeMessages: Holds localization messages for the application.

1.2. keplerGl Reducer

The keplerGl reducer handles updates to the Kepler.gl map state, responding to actions like:

  • LOAD_REMOTE_MAP: Updates the map state with data loaded from a remote URL.
  • LOAD_SAMPLE_CONFIGURATIONS: Updates the map state with data loaded from a sample dataset configuration.
  • LOAD_CLOUD_MAP: Updates the map state with data loaded from a cloud provider.
  • EXPORT_FILE_SUCCESS: Updates the map state to reflect the successful export of the map.
  • LOAD_CLOUD_MAP_SUCCESS: Updates the map state to reflect the successful loading of the map.

2. State Updates

Reducers are responsible for updating the application's state in response to actions dispatched from other components. They follow a specific pattern:

  • Receive the current state and an action object.
  • Check the action type.
  • Return a new state based on the action type and payload.

For example, the keplerGl reducer might update the keplerGl state with new data when it receives a LOAD_REMOTE_MAP action.