Skip to content

Commit

Permalink
Simplify relayStylePagination to avoid optional chaining syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Sep 9, 2020
1 parent 608e09c commit 7a6feae
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/utilities/policies/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,35 @@ export function relayStylePagination<TNode = Reference>(
},

merge(existing = makeEmptyData(), incoming, { args }) {
const incomingEdges = incoming.edges?.slice(0);
if (incoming.pageInfo && incomingEdges) {
const incomingEdges = incoming.edges ? incoming.edges.slice(0) : [];
if (incoming.pageInfo) {
updateCursor(incomingEdges, 0, incoming.pageInfo.startCursor);
updateCursor(incomingEdges, -1, incoming.pageInfo.endCursor);
}

let prefix = existing.edges;
let suffix: typeof prefix = [];

if (args?.after) {
if (args && args.after) {
const index = prefix.findIndex(edge => edge.cursor === args.after);
if (index >= 0) {
prefix = prefix.slice(0, index + 1);
// suffix = []; // already true
}
} else if (args?.before) {
} else if (args && args.before) {
const index = prefix.findIndex(edge => edge.cursor === args.before);
suffix = index < 0 ? prefix : prefix.slice(index);
prefix = [];
} else {
} else if (incoming.edges) {
// If we have neither args.after nor args.before, the incoming
// edges cannot be spliced into the existing edges, so they must
// replace the existing edges. See #6592 for a motivating example.
if(incomingEdges)
prefix = [];
prefix = [];
}

const edges = [
...prefix,
...(incomingEdges || []),
...incomingEdges,
...suffix,
];

Expand Down

0 comments on commit 7a6feae

Please sign in to comment.