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

allow json callback customisation #14795

Closed
wants to merge 4 commits into from

Conversation

petebacondarwin
Copy link
Contributor

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
feat

What is the current behavior? (You can also link to an open issue here)
hard-coded jsonp callback handling

What is the new behavior (if this is a feature change)?
overridable $jsonpCallbacks service that offers a place where customisation can be applied

Does this PR introduce a breaking change?
No

Please check if the PR fulfills these requirements

Other information:

See the commits

…e handled

You can now override this service if you have specific requirements about
the behaviour and formatting of the JSON_CALLBACK that is sent to the server
for `$http.jsonp` requests.
browserTrigger(script, "load");

expect(callback).toHaveBeenCalledOnce();
});


it('should clean up the callback and remove the script', function() {
spyOn($jsonpCallbacks, 'wasCalled').and.callThrough();
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope

@gkalpak
Copy link
Member

gkalpak commented Jun 17, 2016

A few minor comments - LGTM otherwise.
IE doesn't seem to share my opinion though 😛

Use the built-in service to handling callbacks to `$http.jsonp` requests.

Closes angular#3073
@petebacondarwin
Copy link
Contributor Author

petebacondarwin commented Jun 18, 2016

I fixed up IE... the problem was that occasionally, in the test, it was actually triggering the script callback at some point in the future, after the test had completed. When this happened the status of the response was a 404. So I put in a check that the status of the response is a 200 before trying to get hold of the response.

…e handled

You can now override this service if you have specific requirements about
the behaviour and formatting of the JSON_CALLBACK that is sent to the server
for `$http.jsonp` requests.
Use the built-in service to handling callbacks to `$http.jsonp` requests.

Closes angular#3073
@petebacondarwin
Copy link
Contributor Author

@gkalpak thanks for the review. PTAL

callbacks[callbackId] = noop;
var callbackPath = callbacks.createCallback(url);
var jsonpDone = jsonpReq(url, callbackPath, function(status, text) {
var response = (status === 200) && callbacks.getResponse(callbackPath);
Copy link
Member

Choose a reason for hiding this comment

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

Minor: I would add a note that status is set in jsonpReq() and it can be either -1, 404 or 200.
The first time I saw this, I thought: "What if it is in the (200, 300) range?"

@gkalpak
Copy link
Member

gkalpak commented Jun 21, 2016

LGTM 👍

@petebacondarwin
Copy link
Contributor Author

Thanks. I'll comment on the status codes and merge

petebacondarwin added a commit that referenced this pull request Jun 21, 2016
Use the built-in service to handling callbacks to `$http.jsonp` requests.

Closes #3073
Closes #14795
petebacondarwin added a commit that referenced this pull request Jun 21, 2016
…e handled

You can now override this service if you have specific requirements about
the behaviour and formatting of the JSON_CALLBACK that is sent to the server
for `$http.jsonp` requests.

Closes #14795
petebacondarwin added a commit that referenced this pull request Jun 21, 2016
Use the built-in service to handling callbacks to `$http.jsonp` requests.

Closes #3073
Closes #14795
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