From 4e96d7d5ec9a9df07a4dde7455b34c2be53a6dce Mon Sep 17 00:00:00 2001 From: Bruno Lemos Date: Thu, 6 Dec 2018 02:12:59 -0200 Subject: [PATCH] Enable React.memo for card components --- .../cards/partials/rows/BranchRow.tsx | 4 +- .../cards/partials/rows/CommentRow.tsx | 4 +- .../cards/partials/rows/CommitListRow.tsx | 4 +- .../cards/partials/rows/CommitRow.tsx | 4 +- .../partials/rows/IssueOrPullRequestRow.tsx | 160 +++++++++--------- .../cards/partials/rows/ReleaseRow.tsx | 4 +- .../cards/partials/rows/RepositoryListRow.tsx | 4 +- .../cards/partials/rows/RepositoryRow.tsx | 4 +- .../cards/partials/rows/UserListRow.tsx | 4 +- .../cards/partials/rows/UserRow.tsx | 4 +- .../cards/partials/rows/WikiPageListRow.tsx | 4 +- .../cards/partials/rows/WikiPageRow.tsx | 4 +- 12 files changed, 103 insertions(+), 101 deletions(-) diff --git a/packages/components/src/components/cards/partials/rows/BranchRow.tsx b/packages/components/src/components/cards/partials/rows/BranchRow.tsx index 2fba3069..2f5762df 100644 --- a/packages/components/src/components/cards/partials/rows/BranchRow.tsx +++ b/packages/components/src/components/cards/partials/rows/BranchRow.tsx @@ -20,7 +20,7 @@ export interface BranchRowProps { export interface BranchRowState {} -export function BranchRow(props: BranchRowProps) { +export const BranchRow = React.memo((props: BranchRowProps) => { const theme = useTheme() const { @@ -84,4 +84,4 @@ export function BranchRow(props: BranchRowProps) { ) -} +}) diff --git a/packages/components/src/components/cards/partials/rows/CommentRow.tsx b/packages/components/src/components/cards/partials/rows/CommentRow.tsx index dc47568b..d18cbb97 100644 --- a/packages/components/src/components/cards/partials/rows/CommentRow.tsx +++ b/packages/components/src/components/cards/partials/rows/CommentRow.tsx @@ -24,7 +24,7 @@ export interface CommentRowProps { export interface CommentRowState {} -export function CommentRow(props: CommentRowProps) { +export const CommentRow = React.memo((props: CommentRowProps) => { const theme = useTheme() const { @@ -87,4 +87,4 @@ export function CommentRow(props: CommentRowProps) { ) -} +}) diff --git a/packages/components/src/components/cards/partials/rows/CommitListRow.tsx b/packages/components/src/components/cards/partials/rows/CommitListRow.tsx index a1e0e673..fbf27a86 100644 --- a/packages/components/src/components/cards/partials/rows/CommitListRow.tsx +++ b/packages/components/src/components/cards/partials/rows/CommitListRow.tsx @@ -11,7 +11,7 @@ export interface CommitListRowProps { commits: GitHubPushedCommit[] } -export function CommitListRow(props: CommitListRowProps) { +export const CommitListRow = React.memo((props: CommitListRowProps) => { const renderItem: RenderItem = ({ showMoreItemsIndicator, item: commit, @@ -36,4 +36,4 @@ export function CommitListRow(props: CommitListRowProps) { if (!(commits && commits.length > 0)) return null return -} +}) diff --git a/packages/components/src/components/cards/partials/rows/CommitRow.tsx b/packages/components/src/components/cards/partials/rows/CommitRow.tsx index e02adaaa..042a2578 100644 --- a/packages/components/src/components/cards/partials/rows/CommitRow.tsx +++ b/packages/components/src/components/cards/partials/rows/CommitRow.tsx @@ -30,7 +30,7 @@ export interface CommitRowProps { export interface CommitRowState {} -export function CommitRow(props: CommitRowProps) { +export const CommitRow = React.memo((props: CommitRowProps) => { const theme = useTheme() const { @@ -121,4 +121,4 @@ export function CommitRow(props: CommitRowProps) { ) -} +}) diff --git a/packages/components/src/components/cards/partials/rows/IssueOrPullRequestRow.tsx b/packages/components/src/components/cards/partials/rows/IssueOrPullRequestRow.tsx index db54e372..c98118a2 100644 --- a/packages/components/src/components/cards/partials/rows/IssueOrPullRequestRow.tsx +++ b/packages/components/src/components/cards/partials/rows/IssueOrPullRequestRow.tsx @@ -35,89 +35,91 @@ const styles = StyleSheet.create({ }, }) -export function IssueOrPullRequestRow(props: IssueOrPullRequestRowProps) { - const theme = useTheme() +export const IssueOrPullRequestRow = React.memo( + (props: IssueOrPullRequestRowProps) => { + const theme = useTheme() - const { - addBottomAnchor, - avatarURL, - iconColor, - iconName, - isRead, - issueOrPullRequestNumber, - smallLeftColumn, - title: _title, - url, - userLinkURL, - username, - } = props + const { + addBottomAnchor, + avatarURL, + iconColor, + iconName, + isRead, + issueOrPullRequestNumber, + smallLeftColumn, + title: _title, + url, + userLinkURL, + username, + } = props - const title = trimNewLinesAndSpaces(_title) - if (!title) return null + const title = trimNewLinesAndSpaces(_title) + if (!title) return null - const byText = username ? `@${username}` : '' + const byText = username ? `@${username}` : '' - return ( - - - {Boolean(username) && ( - = 0)} - linkURL={userLinkURL} - small - style={getCardStylesForTheme(theme).avatar} - username={username} - /> - )} - - - - + - - {title} - {Boolean(byText) && ( - - {' '} - by {byText} - - )} - - + {Boolean(username) && ( + = 0)} + linkURL={userLinkURL} + small + style={getCardStylesForTheme(theme).avatar} + username={username} + /> + )} + - + + + + {title} + {Boolean(byText) && ( + + {' '} + by {byText} + + )} + + + + + - - ) -} + ) + }, +) diff --git a/packages/components/src/components/cards/partials/rows/ReleaseRow.tsx b/packages/components/src/components/cards/partials/rows/ReleaseRow.tsx index 8c6a440a..10dc8593 100644 --- a/packages/components/src/components/cards/partials/rows/ReleaseRow.tsx +++ b/packages/components/src/components/cards/partials/rows/ReleaseRow.tsx @@ -29,7 +29,7 @@ export interface ReleaseRowProps { export interface ReleaseRowState {} -export function ReleaseRow(props: ReleaseRowProps) { +export const ReleaseRow = React.memo((props: ReleaseRowProps) => { const theme = useTheme() const { @@ -169,4 +169,4 @@ export function ReleaseRow(props: ReleaseRowProps) { )} ) -} +}) diff --git a/packages/components/src/components/cards/partials/rows/RepositoryListRow.tsx b/packages/components/src/components/cards/partials/rows/RepositoryListRow.tsx index 5c13bfa9..c86e6b13 100644 --- a/packages/components/src/components/cards/partials/rows/RepositoryListRow.tsx +++ b/packages/components/src/components/cards/partials/rows/RepositoryListRow.tsx @@ -15,7 +15,7 @@ export interface RepositoryListRowProps { repos: GitHubRepo[] } -export function RepositoryListRow(props: RepositoryListRowProps) { +export const RepositoryListRow = React.memo((props: RepositoryListRowProps) => { const renderItem: RenderItem = ({ item: repo, showMoreItemsIndicator, @@ -45,4 +45,4 @@ export function RepositoryListRow(props: RepositoryListRowProps) { if (!(repos && repos.length > 0)) return null return -} +}) diff --git a/packages/components/src/components/cards/partials/rows/RepositoryRow.tsx b/packages/components/src/components/cards/partials/rows/RepositoryRow.tsx index a493211f..21f0a212 100644 --- a/packages/components/src/components/cards/partials/rows/RepositoryRow.tsx +++ b/packages/components/src/components/cards/partials/rows/RepositoryRow.tsx @@ -22,7 +22,7 @@ export interface RepositoryRowProps { export interface RepositoryRowState {} -export function RepositoryRow(props: RepositoryRowProps) { +export const RepositoryRow = React.memo((props: RepositoryRowProps) => { const theme = useTheme() const { @@ -102,4 +102,4 @@ export function RepositoryRow(props: RepositoryRowProps) { ) -} +}) diff --git a/packages/components/src/components/cards/partials/rows/UserListRow.tsx b/packages/components/src/components/cards/partials/rows/UserListRow.tsx index 889f8242..d7ff6646 100644 --- a/packages/components/src/components/cards/partials/rows/UserListRow.tsx +++ b/packages/components/src/components/cards/partials/rows/UserListRow.tsx @@ -11,7 +11,7 @@ export interface UserListRowProps { users: GitHubUser[] } -export function UserListRow(props: UserListRowProps) { +export const UserListRow = React.memo((props: UserListRowProps) => { const renderItem: RenderItem = ({ item: user, showMoreItemsIndicator, @@ -35,4 +35,4 @@ export function UserListRow(props: UserListRowProps) { if (!(users && users.length > 0)) return null return -} +}) diff --git a/packages/components/src/components/cards/partials/rows/UserRow.tsx b/packages/components/src/components/cards/partials/rows/UserRow.tsx index 78d81d84..71f6f1f1 100644 --- a/packages/components/src/components/cards/partials/rows/UserRow.tsx +++ b/packages/components/src/components/cards/partials/rows/UserRow.tsx @@ -19,7 +19,7 @@ export interface UserRowProps { export interface UserRowState {} -export function UserRow(props: UserRowProps) { +export const UserRow = React.memo((props: UserRowProps) => { const theme = useTheme() const { @@ -69,4 +69,4 @@ export function UserRow(props: UserRowProps) { ) -} +}) diff --git a/packages/components/src/components/cards/partials/rows/WikiPageListRow.tsx b/packages/components/src/components/cards/partials/rows/WikiPageListRow.tsx index 145a9158..ab733437 100644 --- a/packages/components/src/components/cards/partials/rows/WikiPageListRow.tsx +++ b/packages/components/src/components/cards/partials/rows/WikiPageListRow.tsx @@ -10,7 +10,7 @@ export interface WikiPageListRowProps { pages: GitHubPage[] } -export function WikiPageListRow(props: WikiPageListRowProps) { +export const WikiPageListRow = React.memo((props: WikiPageListRowProps) => { const renderItem: RenderItem = ({ item: page, showMoreItemsIndicator, @@ -33,4 +33,4 @@ export function WikiPageListRow(props: WikiPageListRowProps) { if (!(pages && pages.length > 0)) return null return -} +}) diff --git a/packages/components/src/components/cards/partials/rows/WikiPageRow.tsx b/packages/components/src/components/cards/partials/rows/WikiPageRow.tsx index 3104e171..c3c12e0b 100644 --- a/packages/components/src/components/cards/partials/rows/WikiPageRow.tsx +++ b/packages/components/src/components/cards/partials/rows/WikiPageRow.tsx @@ -20,7 +20,7 @@ export interface WikiPageRowProps { export interface WikiPageRowState {} -export function WikiPageRow(props: WikiPageRowProps) { +export const WikiPageRow = React.memo((props: WikiPageRowProps) => { const theme = useTheme() const { @@ -75,4 +75,4 @@ export function WikiPageRow(props: WikiPageRowProps) { ) -} +})