Skip to content

Commit df97766

Browse files
committed
bind Promise.resolve and consistent use of resolveIf
1 parent fc686ab commit df97766

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/data/orders/OrderHelper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type TransformingNetworkClient from '../../communication/TransformingNetw
66
import HelpfulIterator from '../../plumbing/iteration/HelpfulIterator';
77
import makeAsync from '../../plumbing/iteration/makeAsync';
88
import renege from '../../plumbing/renege';
9+
import resolveIf from '../../plumbing/resolveIf';
910
import type Callback from '../../types/Callback';
1011
import type Nullable from '../../types/Nullable';
1112
import { type ThrottlingParameter } from '../../types/parameters';
@@ -118,7 +119,7 @@ export default class OrderHelper extends Helper<OrderData, Order> {
118119
public getPayments(this: OrderHelper & OrderData) {
119120
if (renege(this, this.getPayments, ...arguments)) return;
120121
return (
121-
runIf(this.embedded?.payments, Promise.resolve) ??
122+
resolveIf(this.embedded?.payments) ??
122123
// Getting the payments for an order is an odd case, in the sense that the Mollie API only supports it partially.
123124
// The Mollie API will embed the payments in an order if requested ‒ but unlike with other "embeddables", there
124125
// is no endpoint to get those payments directly. Therefore, the line below rerequests this order, this time with
@@ -154,6 +155,6 @@ export default class OrderHelper extends Helper<OrderData, Order> {
154155
// At the time of writing, the Mollie API does not return a link to the shipments of an order. This is why the line
155156
// below constructs its own URL. If the Mollie API ever starts to return such a link, use it instead for
156157
// consistency.
157-
return runIf(this.embedded?.shipments, Promise.resolve) ?? this.networkClient.list<ShipmentData, Shipment>(getOrderShipmentsPathSegments(this.id), 'shipments');
158+
return resolveIf(this.embedded?.shipments) ?? this.networkClient.list<ShipmentData, Shipment>(getOrderShipmentsPathSegments(this.id), 'shipments');
158159
}
159160
}

src/plumbing/resolveIf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ type Nullish = null | undefined;
77
* [nullish](https://developer.mozilla.org/docs/Glossary/Nullish), in which case it returns that value directly.
88
*/
99
export default function resolveIf<T>(value: T extends Promise<unknown> ? never : T) {
10-
return runIf(value, Promise.resolve) ?? (value as Extract<T, Nullish> | Promise<Exclude<T, Nullish>>);
10+
return runIf(value, Promise.resolve.bind(Promise)) ?? (value as Extract<T, Nullish> | Promise<Exclude<T, Nullish>>);
1111
}

0 commit comments

Comments
 (0)