This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($location): avoid unnecessary $locationChange*
events due to empty hash
#16636
Closed
Closed
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7f524c4
refactor($location): minor changes (unused deps, exported globals, un…
gkalpak 8f28de4
refactor($location): remove unnecessary capturing group in RegExp
gkalpak 8053bc4
refactor($browser): correctly export helper used in specs
gkalpak bbf6900
test($location): add assertion
gkalpak b085893
fix($location): avoid unnecessary `$locationChange*` events due to em…
gkalpak c37c2e4
fixup! fix($location): avoid unnecessary `$locationChange*` events du…
gkalpak cdd1f42
fixup! fix($location): avoid unnecessary `$locationChange*` events du…
gkalpak d736771
fixup! fix($location): avoid unnecessary `$locationChange*` events du…
gkalpak c3ca532
fixup! fix($location): avoid unnecessary `$locationChange*` events du…
gkalpak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -693,10 +693,10 @@ describe('$location', function() { | |
|
||
describe('location watch', function() { | ||
|
||
it('should not update browser if only the empty hash fragment is cleared by updating the search', function() { | ||
it('should not update browser if only the empty hash fragment is cleared', function() { | ||
initService({supportHistory: true}); | ||
mockUpBrowser({initialUrl:'http://new.com/a/b#', baseHref:'/base/'}); | ||
inject(function($rootScope, $browser, $location) { | ||
mockUpBrowser({initialUrl: 'http://new.com/a/b#', baseHref: '/base/'}); | ||
inject(function($browser, $rootScope) { | ||
$browser.url('http://new.com/a/b'); | ||
var $browserUrl = spyOnlyCallsWithArgs($browser, 'url').and.callThrough(); | ||
$rootScope.$digest(); | ||
|
@@ -707,10 +707,11 @@ describe('$location', function() { | |
|
||
it('should not replace browser url if only the empty hash fragment is cleared', function() { | ||
initService({html5Mode: true, supportHistory: true}); | ||
mockUpBrowser({initialUrl:'http://new.com/#', baseHref: '/'}); | ||
inject(function($browser, $location) { | ||
expect($browser.url()).toBe('http://new.com/#'); | ||
mockUpBrowser({initialUrl: 'http://new.com/#', baseHref: '/'}); | ||
inject(function($browser, $location, $window) { | ||
expect($browser.url()).toBe('http://new.com/'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The (non-public) docs for browser.url() say "Without any argument, this method just returns current value of location.href." Isn't this now wrong as the test shows a difference between url() and location.href? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
expect($location.absUrl()).toBe('http://new.com/'); | ||
expect($window.location.href).toBe('http://new.com/#'); | ||
}); | ||
}); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One could move
stripHash
global intobrowser.js
as well for consistency. Otherwise you have two way importing going on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stripHash
is used more in$location
than$browser
and other similar helpers (e.g.stripBaseUrl
,stripFile
) are also in$location
. I only movedtrimEmptyHash
, because it is only used in$browser
now.Even if we had imports/exports (which we don't because everything lives inside the great AngularJS IIFE 😁), I don't see two way importing going on.
$location
would exportstripHash
and$browser
would importstripHash
and exportgetHash
andtrimEmptyHash
.(We definitely have enough URL-specific helpers that we could move them into a separate file and "import" from there 😁)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a little weird having
$browser
depend on$location
. Or was that always the case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know about "always", but it definitely was the case before this PR 😛
(And still is. This PR does not change anything in that regard.)