If you have two gearboxes, and one depends on the value of the first, you just need to update them carefully, and the best solution would be to simply use a special function that will first set the filtering and then request the appropriate events. Also, keep in mind that if fetching events is an asynchronous operation, you should also nest it based on the type of filtering - otherwise there is a chance of a race condition and you will have the wrong events.
I created a redux tile library to deal with the verbosity of raw redux, so I will use it in this example:
import { createSyncTile, createTile } from 'redux-tiles'; const filtering = createSyncTile({ type: ['ui', 'filtering'], fn: ({ params }) => params.type, }); const events = createTile({ type: ['api', 'events'], fn: ({ api, params }) => api.get('/events', { type: params.type }), nesting: ({ type }) => [type], }); // this function will just fetch events, but we will connect to apiEvents // and filter by type const fetchEvents = createTile({ type: ['api', 'fetchEvents'], fn: ({ selectors, getState, dispatch, actions }) => { const type = selectors.ui.filtering(getState()); return dispatch(actions.api.events({ type })); }, });
Bloomca
source share