Skip to content

Commit

Permalink
Simplify composeExchanges helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Dec 2, 2020
1 parent 4ec7780 commit 5d4ccdd
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/core/src/exchanges/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ export const composeExchanges = (exchanges: Exchange[]) => ({
client,
forward,
dispatchDebug,
}: ExchangeInput) =>
exchanges.reduceRight(
(forward, exchange) =>
exchange({
client,
forward,
dispatchDebug(event) {
dispatchDebug({
timestamp: Date.now(),
source: exchange.name,
...event,
});
},
}),
forward
);
}: ExchangeInput) => {
let i = exchanges.length;
while (i--) {
forward = exchanges[i]({
client,
forward,
dispatchDebug(event) {
dispatchDebug({
timestamp: Date.now(),
source: exchanges[i].name,
...event,
});
},
});
}

return forward;
}

0 comments on commit 5d4ccdd

Please sign in to comment.