From b5c5bd4e6ef16fa62145a851f8503b11519764f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Mon, 4 Mar 2024 13:39:23 +0000 Subject: [PATCH] refactor: rewrite `reduce` --- src/store_list.ts | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/store_list.ts b/src/store_list.ts index e3e884e..2bbd70f 100644 --- a/src/store_list.ts +++ b/src/store_list.ts @@ -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 => { const parameters: Record = {