Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b5c5bd4

Browse files
refactor: rewrite reduce
1 parent e0ba757 commit b5c5bd4

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

‎src/store_list.ts‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,13 @@ export function listStores(
2222
// We can't use `async/await` here because that would make the signature
2323
// incompatible with one of the overloads.
2424
// eslint-disable-next-line promise/prefer-await-to-then
25-
return collectIterator(iterator).then((results) =>
26-
results.reduce(
27-
(acc, item) => ({
28-
...acc,
29-
stores: [...acc.stores, ...item.stores],
30-
}),
31-
{ stores: [] },
32-
),
33-
)
25+
return collectIterator(iterator).then((results) => ({ stores: results.flatMap((page) => page.stores) }))
3426
}
3527

36-
const formatListStoreResponse = (rawStores: string[]) =>
37-
rawStores.reduce((acc, rawStore) => {
38-
if (rawStore.startsWith(DEPLOY_STORE_PREFIX)) {
39-
return acc
40-
}
41-
42-
if (rawStore.startsWith(SITE_STORE_PREFIX)) {
43-
return [...acc, rawStore.slice(SITE_STORE_PREFIX.length)]
44-
}
45-
46-
return [...acc, rawStore]
47-
}, [] as string[])
28+
const formatListStoreResponse = (stores: string[]) =>
29+
stores
30+
.filter((store) => !store.startsWith(DEPLOY_STORE_PREFIX))
31+
.map((store) => (store.startsWith(SITE_STORE_PREFIX) ? store.slice(SITE_STORE_PREFIX.length) : store))
4832

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /