This file contains hidden or 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
| const todosSlice = createSlice({ | |
| name: 'cart', | |
| initialState: [], | |
| reducers: { | |
| addItem: { | |
| reducer: (state, action) => { | |
| state.push(action.payload) | |
| }, | |
| prepare: item => { | |
| const id = nanoid() |
This file contains hidden or 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
| const loaderSlice = createSlice({ | |
| name: 'loader', | |
| initialState: { | |
| loading: 'idle', | |
| currentRequestId: undefined, | |
| }, | |
| reducers: {}, | |
| extraReducers: { | |
| [fetchUserById.pending]: (state, action) => { | |
| if (state.loading === 'idle') { |
This file contains hidden or 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
| import { createAsyncThunk } from '@reduxjs/toolkit'; | |
| import fetchMarketItems from '../API/fetchMarketItems'; | |
| export const fetchAllItems = createAsyncThunk( | |
| 'items/fetchAllItems', | |
| fetchMarketItems, | |
| { | |
| condition: (arg, api) => { | |
| return !api.getState().items.length > 0; | |
| }, |
This file contains hidden or 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
| import { createSlice } from '@reduxjs/toolkit'; | |
| const loaderSlice = createSlice({ | |
| name: 'loader', | |
| initialState: false, | |
| reducers: { | |
| startLoader: (state, action) => action.payload, | |
| }, | |
| extraReducers: builder => { | |
| builder |
This file contains hidden or 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
| import { placeOrderThunk } from '../slice/cartSlice'; | |
| import { startLoader } from '../slice/loaderSlice'; | |
| import { error, success } from '../slice/notifySlice'; | |
| import { unwrapResult } from '@reduxjs/toolkit'; | |
| export const handleCartPaymentAsyncAction = () => { | |
| return dispatch => { | |
| dispatch(startLoader(true)); | |
| dispatch(placeOrderThunk()) | |
| // Always return resolved promise with error or payload hence used unwrapResult |
This file contains hidden or 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
| import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'; | |
| import fetchMarketItems from '../API/fetchMarketItems'; | |
| export const fetchAllItems = createAsyncThunk( | |
| 'items/fetchAllItems', | |
| fetchMarketItems, | |
| { | |
| condition: (arg, api) => { | |
| return !api.getState().items.length > 0; | |
| }, |
This file contains hidden or 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
| import { createSlice } from '@reduxjs/toolkit'; | |
| const initialAlert = { | |
| variant: '', | |
| message: '', | |
| }; | |
| const notifySlice = createSlice({ | |
| name: 'notify', | |
| initialState: initialAlert, |
This file contains hidden or 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
| import { NOTIFY_SUCCESS, NOTIFY_ERROR, NOTIFY_RESET } from '../actions/notifyAction'; | |
| const initialAlert = { | |
| variant: '', | |
| message: '', | |
| }; | |
| const notifyReducer = (alert = initialAlert, action) => { | |
| if (action.type === NOTIFY_SUCCESS) { | |
| return { ...alert, variant: 'success', message: action.payload}; |
This file contains hidden or 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
| export const NOTIFY_SUCCESS = 'NOTIFY_SUCCESS'; | |
| export const NOTIFY_ERROR = 'NOTIFY_ERROR'; | |
| export const NOTIFY_RESET = 'NOTIFY_RESET'; | |
| export const notifySuccessAction = payload => ({ type: NOTIFY_SUCCESS, payload }); | |
| export const notifyErrorAction = payload => ({ type: NOTIFY_ERROR, payload }); | |
| export const notifyResetAction = () => ({ type: NOTIFY_RESET }); |
This file contains hidden or 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
| // Redux STORE | |
| const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; | |
| const prodMiddleware = [thunk, immutableStateInvariant, serializableStateInvariant]: | |
| const devMiddleware = [thunk]; | |
| const middleware = process.env.prod ? prodMiddleware : devMiddleware; | |
| const enhancer = composeEnhancers(applyMiddleware(...middleware)); | |
| const ReduxStore = createStore(rootReducer, enhancer); | |
| // RTK STORE |