Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

refactor($http): avoid re-creating execHeaders function #10359

Conversation

pkozlowski-opensource
Copy link
Member

The execHeaders function was being re-defined inside mergeHeaders
function. Additionally it was mutating its arguments thus making code
harder to read / reason about.

There are some other problems with this function (inconsistent treatment for null / undefined headers coming from an object value as compared to being result of a function execution) but let's tackle those one by one.

The execHeaders function was being re-defined inside mergeHeaders
function. Additionally it was mutating its arguments.
@googlebot
Copy link

CLAs look good, thanks!

if (headerContent != null) {
headers[header] = headerContent;
} else {
delete headers[header];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for not needing this

@caitp
Copy link
Contributor

caitp commented Dec 8, 2014

I don't think this is likely to break anyone, and it is a bit simpler without worrying about the "delete" case --- Not too worried about perf implications since it's just $http, and delete is likely to be slower anyways... so basically LGTM. I'd prefer if the executeHeaderFns were defined lower in the source though, (eg below mergeHeaders)

@pkozlowski-opensource
Copy link
Member Author

@caitp I see what you mean by pushing it down in the code but for me this refactoring was enabler for other refactorings. Basically what I would like to do is to push those functions out of each $http call - today those are re-created on each call to $http and there is no good reason for doing it IMO. But yeh, this will come with a separate PR

@caitp
Copy link
Contributor

caitp commented Dec 8, 2014

In fact, they are not actually "re-created" in any engine I'm aware of --- apart from subsequent optimization which can happen in subsequent calls, it doesn't really do anything --- my LGTM is mostly about the getting rid of the "delete" behaviour.

@caitp caitp modified the milestones: 1.3.7, 1.3.8 Dec 9, 2014
@pkozlowski-opensource pkozlowski-opensource modified the milestones: 1.3.8, 1.3.7 Dec 9, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants