Skip to content

Commit

Permalink
perf: lazy merge again
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 6, 2023
1 parent d174e6e commit a72024f
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,25 @@ export function mergeFetchOptions(
};

// Merge params and query
merged.query = {
...defaults?.params,
...defaults?.query,
...input?.params,
...input?.query,
};
delete merged.params;
if (defaults?.params && input?.params) {
merged.params = {
...defaults?.params,
...input?.params,
};
}
if (defaults?.query && input?.query) {
merged.query = {
...defaults?.query,
...input?.query,
};
}

// Merge headers
merged.headers = new Headers(defaults?.headers || {});
for (const [key, value] of new Headers(input?.headers || {})) {
merged.headers.set(key, value);
if (defaults?.headers && input?.headers) {
merged.headers = new Headers(defaults?.headers || {});
for (const [key, value] of new Headers(input?.headers || {})) {
merged.headers.set(key, value);
}
}

return merged;
Expand Down

0 comments on commit a72024f

Please sign in to comment.