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

httpBulk service #636

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
15625ae
feat($browser): xhr returns raw request object
vojtajina Aug 3, 2011
b5e29ec
fix($browser.xhr): change method "JSON" to "JSONP"
vojtajina Aug 10, 2011
83652c8
fix($browser.xhr): respond with internal -2 status on jsonp error
vojtajina Aug 10, 2011
a41a260
fix($browser.xhr): fix IE6, IE7 bug - sync xhr when serving from cache
vojtajina Aug 18, 2011
07a8149
feat($browser.xhr): add timeout option to abort request
vojtajina Aug 18, 2011
ad0918d
feat($cacheFactory): add general purpose $cacheFactory service
IgorMinar Feb 17, 2011
7f34b1c
feat($http): new $http service, removing $xhr.*
vojtajina Aug 4, 2011
90a05b7
feat(mocks.$httpBackend): add $httpBackend mock
vojtajina Aug 16, 2011
a923a59
feat($templateCache): add $templateCache - shared by ng:include, ng:view
vojtajina Oct 18, 2011
4bb90a7
feat(mocks.$browser): add simple addJs() method into $browser mock
vojtajina Aug 23, 2011
7cec45e
feat($httpBackend): extract $browser.xhr into separate service
vojtajina Aug 23, 2011
be6be7d
feat($http): expose pendingRequests and configuration object
vojtajina Oct 18, 2011
5d6c6f0
fix($http): allow multiple json vulnerability prefixes
vojtajina Oct 19, 2011
a1dc31c
fix($resource): to work with $http, $httpBackend services
vojtajina Oct 19, 2011
e5b5861
refactor($http): change callback matching mechanism
vojtajina Oct 27, 2011
50dd480
fix($http): add .send() alias for .retry() to get better stack trace …
vojtajina Oct 31, 2011
44d445c
feat(mock.$httpBackend): throw when nothing to flush, dump data/heade…
vojtajina Oct 31, 2011
22c389c
feat($http): broadcast $http.request event
vojtajina Oct 31, 2011
371171d
feat(mock.$httpBackend): add verifyNoOutstandingRequests method
vojtajina Nov 1, 2011
6db822a
fix(mock.$httpBackend): flush() fires even requests sent during callb…
vojtajina Nov 1, 2011
1e83de4
refactor(mock.$httpBackend): rename when().then() to when().respond()
vojtajina Nov 1, 2011
c46f273
feat(mock.$httpBackend): verify expectations after flush()
vojtajina Nov 1, 2011
2c72f87
to be squashed - fix resource when no error callback
vojtajina Nov 3, 2011
7b9c286
to be squashed $http - callback refactoring
vojtajina Nov 3, 2011
d661ed8
WIP: httpBulk
IgorMinar Nov 3, 2011
d0dd9f2
f: fix tests for IE
IgorMinar Nov 4, 2011
7ebc572
f: whitespace, style, more tests
IgorMinar Nov 4, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions angularFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ angularFiles = {
'src/jqLite.js',
'src/apis.js',
'src/filters.js',
'src/service/cacheFactory.js',
'src/service/cookieStore.js',
'src/service/cookies.js',
'src/service/defer.js',
Expand All @@ -25,10 +26,9 @@ angularFiles = {
'src/service/routeParams.js',
'src/service/sniffer.js',
'src/service/window.js',
'src/service/xhr.bulk.js',
'src/service/xhr.cache.js',
'src/service/xhr.error.js',
'src/service/xhr.js',
'src/service/http.js',
'src/service/httpBackend.js',
'src/service/httpBulk.js',
'src/service/locale.js',
'src/directives.js',
'src/markups.js',
Expand Down
4 changes: 2 additions & 2 deletions docs/content/cookbook/buzz.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ to retrieve Buzz activity and comments.
this.Activity = $resource(
'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
{alt: 'json', callback: 'JSON_CALLBACK'},
{ get: {method: 'JSON', params: {visibility: '@self'}},
replies: {method: 'JSON', params: {visibility: '@self', comments: '@comments'}}
{ get: {method: 'JSONP', params: {visibility: '@self'}},
replies: {method: 'JSONP', params: {visibility: '@self', comments: '@comments'}}
});
}
BuzzController.prototype = {
Expand Down
2 changes: 1 addition & 1 deletion src/AngularPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var browserSingleton;
angularService('$browser', function($log, $sniffer) {
if (!browserSingleton) {
browserSingleton = new Browser(window, jqLite(window.document), jqLite(window.document.body),
XHR, $log, $sniffer);
$log, $sniffer);
}
return browserSingleton;
}, {$inject: ['$log', '$sniffer']});
Expand Down
74 changes: 4 additions & 70 deletions src/Browser.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
'use strict';

//////////////////////////////
// Browser
//////////////////////////////
var XHR = window.XMLHttpRequest || function() {
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e1) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e2) {}
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e3) {}
throw new Error("This browser does not support XMLHttpRequest.");
};


/**
* @ngdoc service
* @name angular.service.$browser
Expand All @@ -36,7 +25,7 @@ var XHR = window.XMLHttpRequest || function() {
* @param {object} $log console.log or an object with the same interface.
* @param {object} $sniffer $sniffer service
*/
function Browser(window, document, body, XHR, $log, $sniffer) {
function Browser(window, document, body, $log, $sniffer) {
var self = this,
rawDocument = document[0],
location = window.location,
Expand All @@ -47,13 +36,12 @@ function Browser(window, document, body, XHR, $log, $sniffer) {

self.isMock = false;

//////////////////////////////////////////////////////////////
// XHR API
//////////////////////////////////////////////////////////////
var idCounter = 0;
var outstandingRequestCount = 0;
var outstandingRequestCallbacks = [];

// TODO(vojta): remove this temporary api
self.$$completeOutstandingRequest = completeOutstandingRequest;
self.$$incOutstandingRequestCount = function() { outstandingRequestCount++; };

/**
* Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks`
Expand All @@ -76,60 +64,6 @@ function Browser(window, document, body, XHR, $log, $sniffer) {
}
}

/**
* @ngdoc method
* @name angular.service.$browser#xhr
* @methodOf angular.service.$browser
*
* @param {string} method Requested method (get|post|put|delete|head|json)
* @param {string} url Requested url
* @param {?string} post Post data to send (null if nothing to post)
* @param {function(number, string)} callback Function that will be called on response
* @param {object=} header additional HTTP headers to send with XHR.
* Standard headers are:
* <ul>
* <li><tt>Content-Type</tt>: <tt>application/x-www-form-urlencoded</tt></li>
* <li><tt>Accept</tt>: <tt>application/json, text/plain, &#42;/&#42;</tt></li>
* <li><tt>X-Requested-With</tt>: <tt>XMLHttpRequest</tt></li>
* </ul>
*
* @description
* Send ajax request
*/
self.xhr = function(method, url, post, callback, headers) {
outstandingRequestCount ++;
if (lowercase(method) == 'json') {
var callbackId = ("angular_" + Math.random() + '_' + (idCounter++)).replace(/\d\./, '');
window[callbackId] = function(data) {
window[callbackId].data = data;
};

var script = self.addJs(url.replace('JSON_CALLBACK', callbackId), function() {
if (window[callbackId].data) {
completeOutstandingRequest(callback, 200, window[callbackId].data);
} else {
completeOutstandingRequest(callback);
}
delete window[callbackId];
body[0].removeChild(script);
});
} else {
var xhr = new XHR();
xhr.open(method, url, true);
forEach(headers, function(value, key) {
if (value) xhr.setRequestHeader(key, value);
});
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
// normalize IE bug (http://bugs.jquery.com/ticket/1450)
var status = xhr.status == 1223 ? 204 : xhr.status;
completeOutstandingRequest(callback, status, xhr.responseText);
}
};
xhr.send(post || '');
}
};

/**
* @private
* Note: this method is used only by scenario runner
Expand Down
21 changes: 11 additions & 10 deletions src/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Route.prototype = {
}
};

function ResourceFactory(xhr) {
this.xhr = xhr;
function ResourceFactory($http) {
this.$http = $http;
}

ResourceFactory.DEFAULT_ACTIONS = {
Expand Down Expand Up @@ -107,11 +107,11 @@ ResourceFactory.prototype = {
}

var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
self.xhr(
action.method,
route.url(extend({}, extractParams(data), action.params || {}, params)),
data,
function(status, response) {
var future = self.$http({
method: action.method,
url: route.url(extend({}, extractParams(data), action.params || {}, params)),
data: data
}).on('success', function(response, status) {
if (response) {
if (action.isArray) {
value.length = 0;
Expand All @@ -123,9 +123,10 @@ ResourceFactory.prototype = {
}
}
(success||noop)(value);
},
error || action.verifyCache,
action.verifyCache);
});

if (error) future.on('error', error);

return value;
};

Expand Down
Loading