Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor(Location): out of router and into platform/common #7962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

NathanWalker
Copy link
Contributor

  • update documentation to reflect changes
  • discuss barrels/decide final placement for several auxiliary location classes.
  • update public_api_spec.ts with new api changes
  • squash and update commit message to reflect breaking changes

@mhevery I don't want this to affect the hard work going into making the ~ 10 KB goal for core.

I could foresee Location, LocationStrategy, HashLocationStrategy, PathLocationStrategy, APP_BASE_HREF going into angular2/common.

Please review when possible and let me know your thoughts.

@NathanWalker NathanWalker force-pushed the refactor-location-core branch from 3027cff to 0739788 Compare April 8, 2016 07:41
@NathanWalker NathanWalker force-pushed the refactor-location-core branch 2 times, most recently from 244ce76 to 322b0f7 Compare April 8, 2016 20:16
@NathanWalker NathanWalker changed the title refactor(Location): out of router and into core refactor(Location): out of router and into core (or common) Apr 8, 2016
@NathanWalker
Copy link
Contributor Author

Ok. I just added 1 more commit that provides a 2nd alternative refactoring of Location into common.
You can now compare both 1st and 2nd commits to see both refactor paths.

After working with the first refactor pass into core (the 1st commit), it occurred to me that a Location service (IMO) is perhaps, not a core feature. There are many applications that never need a Location service, however it is common.

For this reason, I wanted to provide an alternative refactor which instead wraps Location into angular2/common. This is also advantageous as it does not affect core. With the 2nd commit, the breaking changes would be:

BEFORE:

import {
  PlatformLocation,
  Location,
  LocationStrategy,
  HashLocationStrategy,
  PathLocationStrategy,
  APP_BASE_HREF}
from 'angular2/router';

AFTER:

import {PlatformLocation} from 'angular2/src/facade/platform_location';
import {
  Location,
  LocationStrategy,
  HashLocationStrategy,
  PathLocationStrategy,
  APP_BASE_HREF}
from 'angular2/common';

Since PlatformLocation should not be used directly by a common application developer (more for advanced usage), I believe this is well served in facade and not provided by a barrel.

Please let me know which path you like better and I'll squash/add breaking changes to commit message, then update the documentation throughout the files to appropriately reflect the changes as well as update public_api_spec.ts per your approval.

CI breaking is due only to public_api_spec.ts regarding api changes here.

@PatrickJS
Copy link
Contributor

you will probably have to wait for this to be merged #7984

@PatrickJS
Copy link
Contributor

we also need to merge History class before refactoring the router location. At the moment, the current router Location handles both Location and History

@NathanWalker
Copy link
Contributor Author

Thanks for heads up @gdi2290, is there an issue or PR for merging History class?
I could create one?

Also I would greatly appreciate your feedback on this PR.
Main goal is to make Location service available without including the router package.
I'm open to any refactor paths to achieve that; the 2 here are just a way forward that appears clean and makes sense to me.

@mhevery mhevery self-assigned this Apr 9, 2016
@mhevery
Copy link
Contributor

mhevery commented Apr 9, 2016

Hi @NathanWalker, thanks for your PR. I don't think that Location should be part of the core since there could be platforms which do not have location concept. Also different platform may have different shape of Location, for example stack or a tree, hence it is hard to generalize.

I could see how you may want to share the Location between Browser and Server but I don't think it should be part of the core. I would be happy to hear arguments to the contrary.

@NathanWalker
Copy link
Contributor Author

Agreed. On my 2nd commit I show an alternate refactor path placing it in angular2/common instead, however I assume that still ends up being bundled in angular2.dev.js?

Would it make sense to have a separate barrel for this, perhaps angular2/location which would get bundled to 'angular2/bundles/location.js'?

Just trying to create a path forward for those trying to upgrade from Angular 1.x which provided $location as a core service. My company's large Angular 1.x app for instance has an unauthenticated portion of our app which does not use the router however uses $location extensively for various marketing reasons. Therefore, we are in process of upgrading to 2.0 and facing the scenario of having to include the router bundle of 76 KB in those unauthenticated areas just to get access to the Location service :(

@mhevery
Copy link
Contributor

mhevery commented Apr 9, 2016

I think Location should be moved to src/platform/browser or src/platform/common. If you could move it there I would be fine with it. Could you update the PR and squash it?

@NathanWalker NathanWalker force-pushed the refactor-location-core branch 3 times, most recently from 1f9e9fc to e56b777 Compare April 10, 2016 05:48
@NathanWalker
Copy link
Contributor Author

I moved it into src/platform/browser. I like it; makes a lot of sense to me.
Squashed commit and added breaking change block to message.

I'll update the documentation throughout the src by Monday/Tuesday. In meantime, when you can, please review these changes and let me know if you'd like anything else changed. Thanks for your attention to this.

@NathanWalker NathanWalker force-pushed the refactor-location-core branch from e56b777 to cf657db Compare April 10, 2016 06:15
@NathanWalker NathanWalker changed the title refactor(Location): out of router and into core (or common) refactor(Location): out of router and into platform/browser Apr 10, 2016
@@ -1,8 +1,8 @@
import {Directive} from 'angular2/core';
import {Location} from 'angular2/src/platform/browser/location';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general one should never import anything between libraries which includes src in the URL. You can think of Angular2 and Router as separate libraries.

The correct import should be from angular2/platform/... Which means that the Location and friends need to be re-exported from there. Think of src as private and angular2/platform as public. Library can only import from another library public API.

This is a general issue I have seen in many imports. Please canonicalize them.

@mhevery mhevery added pr_state: LGTM action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Apr 10, 2016
@mhevery
Copy link
Contributor

mhevery commented Apr 10, 2016

Other than inconsistent import's this looks good to me. Please ping when ready so that we can merge it.

@NathanWalker NathanWalker force-pushed the refactor-location-core branch 2 times, most recently from 56708ac to febd6f1 Compare April 11, 2016 16:38
@PatrickJS PatrickJS mentioned this pull request Apr 12, 2016
@mhevery
Copy link
Contributor

mhevery commented Apr 12, 2016

Looking good. You have a broken test:

    Expected [ '-UrlChangeEvent', '-UrlChangeListener' ] to equal [  ].
    main/</</<@/home/travis/build/angular/angular/dist/js/dev/es5/angular2/test/public_api_spec.js:200:17 <- diffing_plugin_wrapper-output_path-V43qaiXg.tmp/angular2/test/public_api_spec.ts:213:8
    _it/<@/home/travis/build/angular/angular/dist/js/dev/es5/angular2/src/testing/testing_internal.js:170:17 <- diffing_plugin_wrapper-output_path-V43qaiXg.tmp/angular2/src/testing/testing_internal.ts:171:21

Can you have a look at it? Otherwise this is good to go.

@NathanWalker NathanWalker force-pushed the refactor-location-core branch 9 times, most recently from 22824aa to c359249 Compare April 12, 2016 22:39
@NathanWalker
Copy link
Contributor Author

Whenever I try to fix it for Dart it breaks for JS and vice versa.
Fixing the above error for JS (in saucelabs) then creates this Dart error which is the opposite:

[19:45:52] Starting 'test.unit.dart/ci'...
[19:45:52] Starting 'test.dart.dartium_symlink'...
[19:45:52] Finished 'test.dart.dartium_symlink' after 23 ms
[19:45:52] Starting '!test.unit.dart/run/angular2'...
...
00:56 +1952 ~4 -1: public API should fail if public API for ngPlatformCommon has changed           
  Expected: has different properties
    Actual: ['+UrlChangeEvent', '+UrlChangeListener']
     Which: is equal to [+UrlChangeEvent, +UrlChangeListener]. Expected: []

It appears Dart expects them whereas JS (saucelabs) does not:

[00:46:11] Starting 'test.unit.js.sauce/ci'...
...
Firefox 42.0.0 (Linux 0.0.0) public API should fail if public API for ngPlatformCommon has changed FAILED
    Expected [ '-UrlChangeEvent', '-UrlChangeListener' ] to equal [  ].
    main/</</<@/home/travis/build/angular/angular/dist/js/dev/es5/angular2/test/public_api_spec.js:200:17

Am I missing something? Maybe a separate Dart file I'm not seeing?

@mhevery
Copy link
Contributor

mhevery commented Apr 13, 2016

I think because UrlChangeEvent is an interface it only shows up in Dart. Adding UrlChangeEvent:dart should fix the problem.

@NathanWalker NathanWalker force-pushed the refactor-location-core branch from c359249 to c0e637b Compare April 13, 2016 00:59
@NathanWalker
Copy link
Contributor Author

You're brilliant @mhevery. Don't let nobody tell ya' different.
That got it, thanks!

@NathanWalker NathanWalker force-pushed the refactor-location-core branch from c0e637b to d8d64fd Compare April 14, 2016 14:30
closes angular#4943

BREAKING CHANGE:

`Location` and other related providers have been moved out of `router` and into `platform/common`. `BrowserPlatformLocation` is not meant to be used directly however advanced configurations may use it via the following import change.

Before:

```
import {
  PlatformLocation,
  Location,
  LocationStrategy,
  HashLocationStrategy,
  PathLocationStrategy,
  APP_BASE_HREF}
from 'angular2/router';

import {BrowserPlatformLocation} from 'angular2/src/router/location/browser_platform_location';
```

After:

```
import {
  PlatformLocation,
  Location,
  LocationStrategy,
  HashLocationStrategy,
  PathLocationStrategy,
  APP_BASE_HREF}
from 'angular2/platform/common';

import {BrowserPlatformLocation} from 'angular2/src/platform/browser/location/browser_platform_location';
```
@NathanWalker NathanWalker force-pushed the refactor-location-core branch from d8d64fd to 1254f01 Compare April 15, 2016 00:52
@mhevery mhevery added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Apr 15, 2016
@mhevery
Copy link
Contributor

mhevery commented Apr 15, 2016

Thank you. Added the right labels to get it merged...

@mary-poppins
Copy link

Merging PR #7962 on behalf of @robertmesserle to branch presubmit-robertmesserle-pr-7962.

@Delagen
Copy link
Contributor

Delagen commented Apr 26, 2016

+1 #8240

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants