Skip to content

Commit

Permalink
rename: 'fetch_everything' to 'everyting'
Browse files Browse the repository at this point in the history
  • Loading branch information
chase-moskal committed Jul 4, 2023
1 parent 3f641d8 commit 97178dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
19 changes: 7 additions & 12 deletions s/shopify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import {Remote} from "./parts/remote/remote.js"
import {concurrent} from "./utils/concurrent.js"
import {ImageFormat} from "./requests/units/image.js"
import {paginate} from "./parts/pagination/paginate.js"
import {GqlShop, make_request_for_shop} from "./requests/shop.js"
Expand Down Expand Up @@ -115,18 +116,12 @@ export class Shopify {
)).productRecommendations
}

async fetch_everything() {
const [shop, products, collections] = await Promise.all([
this.shop(),
Shopify.all(this.products()),
Shopify.all(this.collections()),
])

return {
shop,
products,
collections,
}
async everything() {
return concurrent({
shop: this.shop(),
products: Shopify.all(this.products()),
collections: Shopify.all(this.collections()),
})
}
}

13 changes: 13 additions & 0 deletions s/utils/concurrent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

export async function concurrent<O extends {}>(o: O) {
const keys = Object.keys(o)
const awaitables = Object.values(o)

const values = await Promise.all(awaitables)

const result: any = {}
keys.forEach((key, i) => result[key] = values[i])

return result as {[P in keyof O]: Awaited<O[P]>}
}

0 comments on commit 97178dc

Please sign in to comment.