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

Commit 9b35dfb

Browse files
shahatapetebacondarwin
authored andcommitted
refactor($browser): remove private polling mechanism
The only feature of Angular using this mechanism was `$cookies`, which no longer mirrors the browser cookie values and so does not need to poll. Closes #11222
1 parent 53c6636 commit 9b35dfb

File tree

4 files changed

+0
-83
lines changed

4 files changed

+0
-83
lines changed

src/ng/browser.js

-43
Original file line numberDiff line numberDiff line change
@@ -73,56 +73,13 @@ function Browser(window, document, $log, $sniffer) {
7373
* @param {function()} callback Function that will be called when no outstanding request
7474
*/
7575
self.notifyWhenNoOutstandingRequests = function(callback) {
76-
// force browser to execute all pollFns - this is needed so that cookies and other pollers fire
77-
// at some deterministic time in respect to the test runner's actions. Leaving things up to the
78-
// regular poller would result in flaky tests.
79-
forEach(pollFns, function(pollFn) { pollFn(); });
80-
8176
if (outstandingRequestCount === 0) {
8277
callback();
8378
} else {
8479
outstandingRequestCallbacks.push(callback);
8580
}
8681
};
8782

88-
//////////////////////////////////////////////////////////////
89-
// Poll Watcher API
90-
//////////////////////////////////////////////////////////////
91-
var pollFns = [],
92-
pollTimeout;
93-
94-
/**
95-
* @name $browser#addPollFn
96-
*
97-
* @param {function()} fn Poll function to add
98-
*
99-
* @description
100-
* Adds a function to the list of functions that poller periodically executes,
101-
* and starts polling if not started yet.
102-
*
103-
* @returns {function()} the added function
104-
*/
105-
self.addPollFn = function(fn) {
106-
if (isUndefined(pollTimeout)) startPoller(100, setTimeout);
107-
pollFns.push(fn);
108-
return fn;
109-
};
110-
111-
/**
112-
* @param {number} interval How often should browser call poll functions (ms)
113-
* @param {function()} setTimeout Reference to a real or fake `setTimeout` function.
114-
*
115-
* @description
116-
* Configures the poller to run in the specified intervals, using the specified
117-
* setTimeout fn and kicks it off.
118-
*/
119-
function startPoller(interval, setTimeout) {
120-
(function check() {
121-
forEach(pollFns, function(pollFn) { pollFn(); });
122-
pollTimeout = setTimeout(check, interval);
123-
})();
124-
}
125-
12683
//////////////////////////////////////////////////////////////
12784
// URL API
12885
//////////////////////////////////////////////////////////////

src/ngMock/angular-mocks.js

-6
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ angular.mock.$Browser.prototype = {
138138
});
139139
},
140140

141-
addPollFn: function(pollFn) {
142-
this.pollFns.push(pollFn);
143-
return pollFn;
144-
},
145-
146141
url: function(url, replace, state) {
147142
if (angular.isUndefined(state)) {
148143
state = null;
@@ -2148,7 +2143,6 @@ if (window.jasmine || window.mocha) {
21482143

21492144
if (injector) {
21502145
injector.get('$rootElement').off();
2151-
injector.get('$browser').pollFns.length = 0;
21522146
}
21532147

21542148
// clean up jquery's fragment cache

test/ng/browserSpecs.js

-33
Original file line numberDiff line numberDiff line change
@@ -249,37 +249,6 @@ describe('browser', function() {
249249
});
250250

251251

252-
describe('poller', function() {
253-
254-
it('should call functions in pollFns in regular intervals', function() {
255-
var log = '';
256-
browser.addPollFn(function() {log+='a';});
257-
browser.addPollFn(function() {log+='b';});
258-
expect(log).toEqual('');
259-
fakeWindow.setTimeout.flush();
260-
expect(log).toEqual('ab');
261-
fakeWindow.setTimeout.flush();
262-
expect(log).toEqual('abab');
263-
});
264-
265-
it('should startPoller', function() {
266-
expect(fakeWindow.timeouts.length).toEqual(0);
267-
268-
browser.addPollFn(function() {});
269-
expect(fakeWindow.timeouts.length).toEqual(1);
270-
271-
//should remain 1 as it is the check fn
272-
browser.addPollFn(function() {});
273-
expect(fakeWindow.timeouts.length).toEqual(1);
274-
});
275-
276-
it('should return fn that was passed into addPollFn', function() {
277-
var fn = function() { return 1; };
278-
var returnedFn = browser.addPollFn(fn);
279-
expect(returnedFn).toBe(fn);
280-
});
281-
});
282-
283252
describe('url', function() {
284253
var pushState, replaceState, locationReplace;
285254

@@ -723,7 +692,6 @@ describe('browser', function() {
723692
fakeWindow.location.href = newUrl;
724693
});
725694
$provide.value('$browser', browser);
726-
browser.pollFns = [];
727695

728696
sniffer.history = options.history;
729697
$provide.value('$sniffer', sniffer);
@@ -846,7 +814,6 @@ describe('browser', function() {
846814

847815
beforeEach(module(function($provide, $locationProvider) {
848816
$provide.value('$browser', browser);
849-
browser.pollFns = [];
850817
}));
851818

852819
it('should not interfere with legacy browser url replace behavior', function() {

test/ng/locationSpec.js

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ describe('$location', function() {
9999

100100
/* global Browser: false */
101101
var b = new Browser($window, $document, fakeLog, sniffer);
102-
b.pollFns = [];
103102
return b;
104103
};
105104
});

0 commit comments

Comments
 (0)