Add some memoization (#1947)

zio/stable
dan 2023-11-17 02:52:41 +00:00 committed by GitHub
parent e358c3cc30
commit a10adf8908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import React, {MutableRefObject} from 'react' import React, {memo, MutableRefObject} from 'react'
import { import {
ActivityIndicator, ActivityIndicator,
Dimensions, Dimensions,
@ -31,7 +31,7 @@ const EMPTY_FEED_ITEM = {_reactKey: '__empty__'}
const ERROR_ITEM = {_reactKey: '__error__'} const ERROR_ITEM = {_reactKey: '__error__'}
const LOAD_MORE_ERROR_ITEM = {_reactKey: '__load_more_error__'} const LOAD_MORE_ERROR_ITEM = {_reactKey: '__load_more_error__'}
export function Feed({ let Feed = ({
feed, feed,
feedParams, feedParams,
style, style,
@ -65,7 +65,7 @@ export function Feed({
desktopFixedHeightOffset?: number desktopFixedHeightOffset?: number
ListHeaderComponent?: () => JSX.Element ListHeaderComponent?: () => JSX.Element
extraData?: any extraData?: any
}) { }): React.ReactNode => {
const pal = usePalette('default') const pal = usePalette('default')
const theme = useTheme() const theme = useTheme()
const {track} = useAnalytics() const {track} = useAnalytics()
@ -273,6 +273,8 @@ export function Feed({
</View> </View>
) )
} }
Feed = memo(Feed)
export {Feed}
const styles = StyleSheet.create({ const styles = StyleSheet.create({
feedFooter: {paddingTop: 20}, feedFooter: {paddingTop: 20},

View File

@ -1,4 +1,4 @@
import React, {useMemo, useState} from 'react' import React, {memo, useMemo, useState} from 'react'
import {StyleSheet, View} from 'react-native' import {StyleSheet, View} from 'react-native'
import { import {
AppBskyFeedDefs, AppBskyFeedDefs,
@ -83,7 +83,7 @@ export function FeedItem({
return null return null
} }
function FeedItemInner({ let FeedItemInner = ({
post, post,
record, record,
reason, reason,
@ -101,7 +101,7 @@ function FeedItemInner({
isThreadChild?: boolean isThreadChild?: boolean
isThreadLastChild?: boolean isThreadLastChild?: boolean
isThreadParent?: boolean isThreadParent?: boolean
}) { }): React.ReactNode => {
const {openComposer} = useComposerControls() const {openComposer} = useComposerControls()
const pal = usePalette('default') const pal = usePalette('default')
const {track} = useAnalytics() const {track} = useAnalytics()
@ -334,6 +334,7 @@ function FeedItemInner({
</Link> </Link>
) )
} }
FeedItemInner = memo(FeedItemInner)
const styles = StyleSheet.create({ const styles = StyleSheet.create({
outer: { outer: {

View File

@ -1,4 +1,4 @@
import React from 'react' import React, {memo} from 'react'
import {StyleSheet, View} from 'react-native' import {StyleSheet, View} from 'react-native'
import {FeedPostSlice} from '#/state/queries/post-feed' import {FeedPostSlice} from '#/state/queries/post-feed'
import {AtUri, moderatePost, ModerationOpts} from '@atproto/api' import {AtUri, moderatePost, ModerationOpts} from '@atproto/api'
@ -9,7 +9,7 @@ import {FeedItem} from './FeedItem'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {makeProfileLink} from 'lib/routes/links' import {makeProfileLink} from 'lib/routes/links'
export function FeedSlice({ let FeedSlice = ({
slice, slice,
dataUpdatedAt, dataUpdatedAt,
ignoreFilterFor, ignoreFilterFor,
@ -19,7 +19,7 @@ export function FeedSlice({
dataUpdatedAt: number dataUpdatedAt: number
ignoreFilterFor?: string ignoreFilterFor?: string
moderationOpts: ModerationOpts moderationOpts: ModerationOpts
}) { }): React.ReactNode => {
const moderations = React.useMemo(() => { const moderations = React.useMemo(() => {
return slice.items.map(item => moderatePost(item.post, moderationOpts)) return slice.items.map(item => moderatePost(item.post, moderationOpts))
}, [slice, moderationOpts]) }, [slice, moderationOpts])
@ -94,6 +94,8 @@ export function FeedSlice({
</> </>
) )
} }
FeedSlice = memo(FeedSlice)
export {FeedSlice}
function ViewFullThread({slice}: {slice: FeedPostSlice}) { function ViewFullThread({slice}: {slice: FeedPostSlice}) {
const pal = usePalette('default') const pal = usePalette('default')

View File

@ -1,4 +1,4 @@
import React from 'react' import React, {memo} from 'react'
import { import {
StyleSheet, StyleSheet,
TouchableOpacity, TouchableOpacity,
@ -105,12 +105,12 @@ interface LoadedProps {
isProfilePreview?: boolean isProfilePreview?: boolean
} }
function ProfileHeaderLoaded({ let ProfileHeaderLoaded = ({
profile, profile,
moderation, moderation,
hideBackButton = false, hideBackButton = false,
isProfilePreview, isProfilePreview,
}: LoadedProps) { }: LoadedProps): React.ReactNode => {
const pal = usePalette('default') const pal = usePalette('default')
const palInverted = usePalette('inverted') const palInverted = usePalette('inverted')
const {currentAccount} = useSession() const {currentAccount} = useSession()
@ -627,6 +627,7 @@ function ProfileHeaderLoaded({
</View> </View>
) )
} }
ProfileHeaderLoaded = memo(ProfileHeaderLoaded)
const styles = StyleSheet.create({ const styles = StyleSheet.create({
banner: { banner: {