Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

964 B
Raw Blame
/* eslint-disable no-console */
// This is only enabled manually for debugging, console is allowed.

import type { Middleware, MiddlewareAPI } from '@reduxjs/toolkit';
import { diff } from 'jsondiffpatch';

/**
 * Super simple logger middleware. Useful for debugging when the redux devtools are awkward.
 */
export const getDebugLoggerMiddleware =
  (options?: { filter?: (action: unknown) => boolean; withDiff?: boolean; withNextState?: boolean }): Middleware =>
  (api: MiddlewareAPI) =>
  (next) =>
  (action) => {
    if (options?.filter?.(action)) {
      return next(action);
    }
    const originalState = api.getState();
    console.log('REDUX: dispatching', action);
    const result = next(action);
    const nextState = api.getState();
    if (options?.withNextState) {
      console.log('REDUX: next state', nextState);
    }
    if (options?.withDiff) {
      console.log('REDUX: diff', diff(originalState, nextState));
    }
    return result;
  };