Skip to content

Commit

Permalink
refactor: rewrite reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Mar 4, 2024
1 parent e0ba757 commit b5c5bd4
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions src/store_list.ts
Expand Up @@ -22,29 +22,13 @@ export function listStores(
// We can't use `async/await` here because that would make the signature
// incompatible with one of the overloads.
// eslint-disable-next-line promise/prefer-await-to-then
return collectIterator(iterator).then((results) =>
results.reduce(
(acc, item) => ({
...acc,
stores: [...acc.stores, ...item.stores],
}),
{ stores: [] },
),
)
return collectIterator(iterator).then((results) => ({ stores: results.flatMap((page) => page.stores) }))
}

const formatListStoreResponse = (rawStores: string[]) =>
rawStores.reduce((acc, rawStore) => {
if (rawStore.startsWith(DEPLOY_STORE_PREFIX)) {
return acc
}

if (rawStore.startsWith(SITE_STORE_PREFIX)) {
return [...acc, rawStore.slice(SITE_STORE_PREFIX.length)]
}

return [...acc, rawStore]
}, [] as string[])
const formatListStoreResponse = (stores: string[]) =>
stores
.filter((store) => !store.startsWith(DEPLOY_STORE_PREFIX))
.map((store) => (store.startsWith(SITE_STORE_PREFIX) ? store.slice(SITE_STORE_PREFIX.length) : store))

const getListIterator = (client: Client, prefix: string): AsyncIterable<ListStoresResponse> => {
const parameters: Record<string, string> = {
Expand Down

0 comments on commit b5c5bd4

Please sign in to comment.