-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#495]: remove sagas from rooms duck
- Loading branch information
Showing
13 changed files
with
115 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
apps/ligretto-frontend/src/app/store/listenerModdleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createListenerMiddleware } from '@reduxjs/toolkit' | ||
|
||
import { addListeners as roomsAddListener } from '#ducks/rooms' | ||
import type { All } from '#types/store' | ||
|
||
export const listenerMiddleware = createListenerMiddleware() | ||
|
||
const startAppListening = listenerMiddleware.startListening.withTypes<All>() | ||
|
||
roomsAddListener(startAppListening) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './slice' | ||
export { roomsRootSaga } from './sagas' | ||
export * from './selectors' | ||
export { addListeners } from './listeners' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { type TypedStartListening } from '@reduxjs/toolkit' | ||
import { replace, push } from 'redux-first-history' | ||
import { generatePath } from 'react-router-dom' | ||
|
||
import { | ||
getRoomsEmitAction, | ||
createRoomEmitAction, | ||
updateRoomsAction as updateRoomsServerAction, | ||
removeRoomAction as removeRoomServerAction, | ||
connectToRoomErrorAction, | ||
connectToRoomEmitAction, | ||
createRoomErrorAction, | ||
createRoomSuccessAction, | ||
} from '@memebattle/ligretto-shared' | ||
|
||
import { routes } from '#shared/constants' | ||
import type { RoomsState } from './slice' | ||
import { getRoomsAction, createRoomAction } from './slice' | ||
import { connectToRoomAction, updateRoomsAction, setErrorRoomsAction, removeRoomAction } from './slice' | ||
|
||
export function addListeners(startListener: TypedStartListening<{ rooms: RoomsState }>) { | ||
startListener({ | ||
actionCreator: getRoomsAction, | ||
effect: (_action, listenerApi) => { | ||
listenerApi.dispatch(getRoomsEmitAction()) | ||
}, | ||
}) | ||
|
||
startListener({ | ||
actionCreator: createRoomAction, | ||
effect: (action, listenerApi) => { | ||
listenerApi.dispatch(createRoomEmitAction(action.payload)) | ||
}, | ||
}) | ||
|
||
startListener({ | ||
actionCreator: connectToRoomAction, | ||
effect: (action, listenerApi) => { | ||
listenerApi.dispatch(connectToRoomEmitAction(action.payload)) | ||
}, | ||
}) | ||
|
||
startListener({ | ||
actionCreator: updateRoomsServerAction, | ||
effect: (action, listenerApi) => { | ||
const rooms = action.payload.rooms | ||
listenerApi.dispatch(updateRoomsAction({ rooms })) | ||
}, | ||
}) | ||
|
||
startListener({ | ||
actionCreator: removeRoomServerAction, | ||
effect: (action, listenerApi) => { | ||
const uuid = action.payload.uuid | ||
listenerApi.dispatch(removeRoomAction({ uuid })) | ||
}, | ||
}) | ||
|
||
startListener({ | ||
actionCreator: connectToRoomErrorAction, | ||
effect: (_action, listenerApi) => { | ||
listenerApi.dispatch(replace(routes.HOME)) | ||
}, | ||
}) | ||
|
||
startListener({ | ||
actionCreator: createRoomSuccessAction, | ||
effect: (action, listenerApi) => { | ||
listenerApi.dispatch(setErrorRoomsAction({ error: null })) | ||
listenerApi.dispatch(push(generatePath(routes.GAME, { roomUuid: action.payload.game.id }))) | ||
}, | ||
}) | ||
|
||
startListener({ | ||
actionCreator: createRoomErrorAction, | ||
effect: (action, listenerApi) => { | ||
listenerApi.dispatch(setErrorRoomsAction({ error: action.payload })) | ||
}, | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters