mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add rtk action type guard
This commit is contained in:
parent
4ac447cf74
commit
662f1321f6
@ -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<AppDispatch, RootState>) => (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');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user