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

Commit 120701b

Browse files
committed
fix($browser.setUrl): make browser.setUrl more efficient
- browser should remember the last value retrieved via browser.getUrl - browser should update window.location only if the new value is different from the current window.location value
1 parent fe52407 commit 120701b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Browser.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ function Browser(window, document, body, XHR, $log) {
3939
var self = this,
4040
rawDocument = document[0],
4141
location = window.location,
42-
setTimeout = window.setTimeout;
42+
setTimeout = window.setTimeout,
43+
lastLocationUrl;
4344

4445
self.isMock = false;
4546

@@ -201,10 +202,13 @@ function Browser(window, document, body, XHR, $log) {
201202
* Sets browser's url
202203
*/
203204
self.setUrl = function(url) {
204-
var existingURL = location.href;
205+
206+
var existingURL = lastLocationUrl;
205207
if (!existingURL.match(/#/)) existingURL += '#';
206208
if (!url.match(/#/)) url += '#';
207-
location.href = url;
209+
if (existingURL != url) {
210+
location.href = url;
211+
}
208212
};
209213

210214
/**
@@ -219,7 +223,7 @@ function Browser(window, document, body, XHR, $log) {
219223
* @returns {string} Browser's url
220224
*/
221225
self.getUrl = function() {
222-
return location.href;
226+
return lastLocationUrl = location.href;
223227
};
224228

225229

0 commit comments

Comments
 (0)