diff --git a/invokeai/frontend/web/src/services/invokeMiddleware.ts b/invokeai/frontend/web/src/services/invokeMiddleware.ts index 9c8544f75e..5579015f79 100644 --- a/invokeai/frontend/web/src/services/invokeMiddleware.ts +++ b/invokeai/frontend/web/src/services/invokeMiddleware.ts @@ -1,14 +1,21 @@ -import { Middleware, MiddlewareAPI } from '@reduxjs/toolkit'; +import { isFulfilled, Middleware, MiddlewareAPI } from '@reduxjs/toolkit'; import { emitSubscribe } from 'app/nodesSocketio/actions'; import { AppDispatch, RootState } from 'app/store'; import { setSessionId } from './apiSlice'; -import { invokeSession } from './thunks/session'; +import { createSession, invokeSession } from './thunks/session'; + +/** + * `redux-toolkit` provides nice matching utilities, which can be used as type guards + * See: https://redux-toolkit.js.org/api/matching-utilities + */ + +const isFulfilledCreateSession = isFulfilled(createSession); export const invokeMiddleware: Middleware = (store: MiddlewareAPI) => (next) => (action) => { const { dispatch } = store; - if (action.type === 'api/createSession/fulfilled' && action?.payload?.id) { + if (isFulfilledCreateSession(action)) { const sessionId = action.payload.id; console.log('createSession.fulfilled');