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

Commit 2120627

Browse files
IgorMinarmgol
authored andcommitted
WIP: remove changeCounter from $location
there are tests failing after this change, need to check if they are legitimate failures
1 parent d10c9ad commit 2120627

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/ng/location.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -832,32 +832,40 @@ function $LocationProvider(){
832832
});
833833

834834
// update browser
835-
var changeCounter = 0;
835+
var initializing = true;
836+
836837
$rootScope.$watch(function $locationWatch() {
837838
var oldUrl = $browser.url();
838839
var oldState = $browser.state();
839840
var currentReplace = $location.$$replace;
840-
var currentStateSent = $location.$$stateSent && changeCounter;
841+
var currentStateSent = $location.$$stateSent;
842+
var origInitializing = initializing;
841843

842-
if (!changeCounter || oldUrl !== $location.absUrl() ||
844+
if (initializing || oldUrl !== $location.absUrl() ||
843845
($location.$$html5 && $sniffer.history && oldState !== $location.$$state)) {
844-
changeCounter++;
846+
initializing = false;
847+
845848
$rootScope.$evalAsync(function() {
846849
if ($rootScope.$broadcast('$locationChangeStart', $location.absUrl(), oldUrl,
847850
$location.$$state, oldState).defaultPrevented) {
848851
$location.$$parse(oldUrl);
849852
$location.$$state = oldState;
850853
} else {
851-
setBrowserUrlWithFallback($location.absUrl(), currentReplace,
852-
currentStateSent ? null : $location.$$state);
854+
if (!origInitializing) {
855+
setBrowserUrlWithFallback($location.absUrl(), currentReplace,
856+
currentStateSent ? null : $location.$$state);
857+
}
858+
853859
afterLocationChange(oldUrl, oldState);
854860
}
855861
});
856862
}
863+
857864
$location.$$stateSent = true;
858865
$location.$$replace = false;
859866

860-
return changeCounter;
867+
// we don't need to return anything because $evalAsync will make the digest loop dirty when
868+
// there is a change
861869
});
862870

863871
return $location;

0 commit comments

Comments
 (0)