How to use the @commercetools-frontend/sdk.createMiddleware function in @commercetools-frontend/sdk

To help you get started, we’ve selected a few @commercetools-frontend/sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commercetools / merchant-center-application-kit / packages / application-shell / src / configure-store.js View on Github external
const mergeObjectValues = object =>
  Object.entries(object).reduce((acc, [, value]) => ({ ...acc, ...value }), {});

const patchedGetCorrelationId = () =>
  getCorrelationId({
    userId: selectUserId({ apolloCache: apolloClient }),
  });

const createInternalReducer = (injectedReducers = {}) =>
  combineReducers({
    requestsInFlight: requestsInFlightReducer,
    notifications: notificationsReducer,
    ...injectedReducers,
  });

const sdkMiddleware = createSdkMiddleware({
  getCorrelationId: patchedGetCorrelationId,
  getProjectKey: selectProjectKeyFromUrl,
  getTeamId: selectTeamIdFromLocalStorage,
});

export const applyDefaultMiddlewares = (...middlewares) =>
  applyMiddleware(...middlewares, thunk, loggerMiddleware);

// We use a factory as it's more practicable for tests
// The application can import the configured store (the default export)
export const createReduxStore = (
  preloadedState = { requestsInFlight: null },
  // additional middleware, used for testing
  additionalMiddlewares = []
) => {
  const store = createStore(