diff options
| author | Misko Hevery | 2011-03-23 09:33:29 -0700 |
|---|---|---|
| committer | Vojta Jina | 2011-08-02 01:00:03 +0200 |
| commit | 8f0dcbab804180828d6859b1340c86cf161209fb (patch) | |
| tree | d13d47d47a1889cb7c96a87cecacd2e25307d51c /src/service/location.js | |
| parent | 1f4b417184ce53af15474de065400f8a686430c5 (diff) | |
| download | angular.js-8f0dcbab804180828d6859b1340c86cf161209fb.tar.bz2 | |
feat(scope): new and improved scope implementation
- Speed improvements (about 4x on flush phase)
- Memory improvements (uses no function closures)
- Break $eval into $apply, $dispatch, $flush
- Introduced $watch and $observe
Breaks angular.equals() use === instead of ==
Breaks angular.scope() does not take parent as first argument
Breaks scope.$watch() takes scope as first argument
Breaks scope.$set(), scope.$get are removed
Breaks scope.$config is removed
Breaks $route.onChange callback has not "this" bounded
Diffstat (limited to 'src/service/location.js')
| -rw-r--r-- | src/service/location.js | 47 |
1 files changed, 17 insertions, 30 deletions
diff --git a/src/service/location.js b/src/service/location.js index 1889266e..23531140 100644 --- a/src/service/location.js +++ b/src/service/location.js @@ -69,18 +69,14 @@ var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+) </doc:example> */ angularServiceInject("$location", function($browser) { - var scope = this, - location = {update:update, updateHash: updateHash}, - lastLocation = {}; + var location = {update: update, updateHash: updateHash}; + var lastLocation = {}; // last state since last update(). - $browser.onHashChange(function() { //register + $browser.onHashChange(bind(this, this.$apply, function() { //register update($browser.getUrl()); - copy(location, lastLocation); - scope.$eval(); - })(); //initialize + }))(); //initialize - this.$onEval(PRIORITY_FIRST, sync); - this.$onEval(PRIORITY_LAST, updateBrowser); + this.$watch(sync); return location; @@ -94,6 +90,8 @@ angularServiceInject("$location", function($browser) { * * @description * Updates the location object. + * Does not immediately update the browser + * Browser is updated at the end of $flush() * * Does not immediately update the browser. Instead the browser is updated at the end of $eval() * cycle. @@ -122,6 +120,8 @@ angularServiceInject("$location", function($browser) { location.href = composeHref(location); } + $browser.setUrl(location.href); + copy(location, lastLocation); } /** @@ -188,34 +188,21 @@ angularServiceInject("$location", function($browser) { if (!equals(location, lastLocation)) { if (location.href != lastLocation.href) { update(location.href); - return; - } - if (location.hash != lastLocation.hash) { - var hash = parseHash(location.hash); - updateHash(hash.hashPath, hash.hashSearch); } else { - location.hash = composeHash(location); - location.href = composeHref(location); + if (location.hash != lastLocation.hash) { + var hash = parseHash(location.hash); + updateHash(hash.hashPath, hash.hashSearch); + } else { + location.hash = composeHash(location); + location.href = composeHref(location); + } + update(location.href); } - update(location.href); } } /** - * If location has changed, update the browser - * This method is called at the end of $eval() phase - */ - function updateBrowser() { - sync(); - - if ($browser.getUrl() != location.href) { - $browser.setUrl(location.href); - copy(location, lastLocation); - } - } - - /** * Compose href string from a location object * * @param {Object} loc The location object with all properties |
