Open danieldanielecki opened 1 year ago
which is basically React Toolkit from https://redux.js.org/introduction/why-rtk-is-redux-today
Actions have split in https://github.com/tamotam-com/tamotam-app/commit/55e8f933c611d7bae936b957044ce88048b6d791 which significantly improved performance. Now, each HTTP
request is independent and speeds up the load of markers on the map.
Last piece of that improvement has been incorporated in https://github.com/tamotam-com/tamotam-app/commit/ad566add9d5c50afb68e64266bb81a81eda121ed
Now, only splitting component to smaller pieces is needed.
Take a look into
store
, whereactions
anddispatchers
are in a single file.However, there's also feedback regarding
EditEventScreen
on https://github.com/AidOnline01/review-daniel/blob/main/1-huge-files.md. Similarly, other files could split up.Example:
About the issue
There is a violation of Single Responsibility principle, which creates huge files and reduces maintability/testability/reusability of codebase.
Example
Example from the code
[EditEventScreen](https://github.com/tamotam-com/tamotam-app/blob/master/screens/EditEventScreen.tsx) ```javascript import * as Location from "expo-location"; import analytics from "@react-native-firebase/analytics"; import crashlytics from "@react-native-firebase/crashlytics"; import useColorScheme from "../hooks/useColorScheme"; import Colors from "../constants/Colors"; import CustomMapStyles from "../constants/CustomMapStyles"; import DateTimePicker from "@react-native-community/datetimepicker"; import MaterialHeaderButton from "../components/MaterialHeaderButton"; import MapView, { Marker, PROVIDER_GOOGLE } from "react-native-maps"; import SelectImage from "../components/SelectImage"; import React, { useCallback, useEffect, useLayoutEffect, useRef, useState, Dispatch, MutableRefObject, SetStateAction, } from "react"; import StyledText from "../components/StyledText"; import { updateEvent } from "../store/actions/events"; import { useDispatch, useSelector } from "react-redux"; import { useNetInfo, NetInfoState } from "@react-native-community/netinfo"; import { ActivityIndicator, Alert, ColorSchemeName, Dimensions, KeyboardAvoidingView, Platform, ScrollView, StyleSheet, TextInput, } from "react-native"; import { Button } from "react-native-paper"; import { Coordinate } from "../interfaces/coordinate"; import { Event } from "../interfaces/event"; import { HeaderButtons, Item } from "react-navigation-header-buttons"; import { Region } from "../interfaces/region"; import { View } from "../components/Themed"; export default function EditEventScreen({ navigation, route }: any) { const colorScheme: ColorSchemeName = useColorScheme(); const dispatch: DispatchHow it could have been done?
```javascript import analytics from "@react-native-firebase/analytics"; import React, { useCallback, useEffect, useLayoutEffect, useState, Dispatch, } from "react"; import { useDispatch, useSelector } from "react-redux"; import { useNetInfo, NetInfoState } from "@react-native-community/netinfo"; import { Event } from "../interfaces/event"; import { Region } from "../interfaces/region"; import LoadingView from '@/components/common/LoadingView.ts'; import InternetConnectionErrorView from '@/components/errors/InternetConnectionErrorView.ts'; import EditEventScreen from '@/components/edit-screen/EditEventScreen.ts'; import EditEventHeaderButtons from '@/components/edit-screen/EditEventHeaderButtons.ts'; import reportError from '@/services/reportError'; import userLocationHandlerCallback from '@/services/edit-event/userLocationHandlerCallback'; export default function EditEventScreen({ navigation, route }: any) { const dispatch: DispatchChanges
So instead of putting everything into one file, I would have splitted it into multiple smaller files (
EditEventScreenStyles.ts, LoadingView.ts, InternetConnectionErrorView.ts, EditEventScreen.ts, reportError, EditEventHeaderButtons, userLocationHandlerCallback
) and renamed it to theEditEventView.ts
.