refactor(common): rename LocationUpgradeService and remove angular/upgrade dependency (#30055)
PR Close #30055
This commit is contained in:
parent
efdbbe1aa6
commit
071ee64d91
|
@ -8,8 +8,5 @@
|
|||
"esm2015": "../esm2015/upgrade/upgrade.js",
|
||||
"fesm5": "../fesm5/upgrade.js",
|
||||
"fesm2015": "../fesm2015/upgrade.js",
|
||||
"sideEffects": false,
|
||||
"peerDependencies": {
|
||||
"@angular/upgrade": "0.0.0-PLACEHOLDER"
|
||||
}
|
||||
"sideEffects": false
|
||||
}
|
|
@ -26,7 +26,7 @@ const DEFAULT_PORTS: {[key: string]: number} = {
|
|||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export class LocationUpgradeService {
|
||||
export class $locationShim {
|
||||
private initalizing = true;
|
||||
private updateBrowser = false;
|
||||
private $$absUrl: string = '';
|
||||
|
@ -664,14 +664,14 @@ export class LocationUpgradeService {
|
|||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export class LocationUpgradeProvider {
|
||||
export class $locationShimProvider {
|
||||
constructor(
|
||||
private ngUpgrade: UpgradeModule, private location: Location,
|
||||
private platformLocation: PlatformLocation, private urlCodec: UrlCodec,
|
||||
private locationStrategy: LocationStrategy) {}
|
||||
|
||||
$get() {
|
||||
return new LocationUpgradeService(
|
||||
return new $locationShim(
|
||||
this.ngUpgrade.$injector, this.location, this.platformLocation, this.urlCodec,
|
||||
this.locationStrategy);
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {downgradeInjectable} from '@angular/upgrade/static';
|
||||
import {LocationUpgradeProvider} from './$location';
|
||||
|
||||
/**
|
||||
* Name of AngularJS module under which $location upgrade services are exported.
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export const LOCATION_UPGRADE_MODULE = 'LOCATION_UPGRADE_MODULE';
|
||||
|
||||
/**
|
||||
* Downgraded $location provider. API should match AngularJS $location and should be a drop-in
|
||||
* replacement.
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export const $locationProvider = downgradeInjectable(LocationUpgradeProvider);
|
|
@ -7,6 +7,5 @@
|
|||
*/
|
||||
|
||||
export * from './location_upgrade_module';
|
||||
export * from './angular_js_module';
|
||||
export * from './$location';
|
||||
export * from './$location_shim';
|
||||
export * from './params';
|
|
@ -10,9 +10,10 @@ import {APP_BASE_HREF, CommonModule, HashLocationStrategy, Location, LocationStr
|
|||
import {Inject, InjectionToken, ModuleWithProviders, NgModule, Optional} from '@angular/core';
|
||||
import {UpgradeModule} from '@angular/upgrade/static';
|
||||
|
||||
import {LocationUpgradeProvider, LocationUpgradeService} from './$location';
|
||||
import {$locationShim, $locationShimProvider} from './$location_shim';
|
||||
import {AngularJSUrlCodec, UrlCodec} from './params';
|
||||
|
||||
|
||||
/**
|
||||
* Configuration options for LocationUpgrade.
|
||||
*
|
||||
|
@ -49,7 +50,7 @@ export class LocationUpgradeModule {
|
|||
providers: [
|
||||
Location,
|
||||
{
|
||||
provide: LocationUpgradeService,
|
||||
provide: $locationShim,
|
||||
useFactory: provide$location,
|
||||
deps: [UpgradeModule, Location, PlatformLocation, UrlCodec, LocationStrategy]
|
||||
},
|
||||
|
@ -101,8 +102,8 @@ export function provideLocationStrategy(
|
|||
export function provide$location(
|
||||
ngUpgrade: UpgradeModule, location: Location, platformLocation: PlatformLocation,
|
||||
urlCodec: UrlCodec, locationStrategy: LocationStrategy) {
|
||||
const $locationProvider = new LocationUpgradeProvider(
|
||||
ngUpgrade, location, platformLocation, urlCodec, locationStrategy);
|
||||
const $locationProvider =
|
||||
new $locationShimProvider(ngUpgrade, location, platformLocation, urlCodec, locationStrategy);
|
||||
|
||||
return $locationProvider.$get();
|
||||
}
|
|
@ -10,7 +10,7 @@ import {CommonModule, PathLocationStrategy} from '@angular/common';
|
|||
import {TestBed, inject} from '@angular/core/testing';
|
||||
import {UpgradeModule} from '@angular/upgrade/static';
|
||||
|
||||
import {LocationUpgradeService} from '../src/$location';
|
||||
import {$locationShim} from '../src/$location_shim';
|
||||
|
||||
import {LocationUpgradeTestModule} from './upgrade_location_test_module';
|
||||
|
||||
|
@ -79,17 +79,16 @@ describe('LocationProvider', () => {
|
|||
upgradeModule.$injector = {get: injectorFactory()};
|
||||
});
|
||||
|
||||
it('should instantiate LocationProvider',
|
||||
inject([LocationUpgradeService], ($location: LocationUpgradeService) => {
|
||||
it('should instantiate LocationProvider', inject([$locationShim], ($location: $locationShim) => {
|
||||
expect($location).toBeDefined();
|
||||
expect($location instanceof LocationUpgradeService).toBe(true);
|
||||
expect($location instanceof $locationShim).toBe(true);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('LocationHtml5Url', function() {
|
||||
let $location: LocationUpgradeService;
|
||||
let $location: $locationShim;
|
||||
let upgradeModule: UpgradeModule;
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -106,8 +105,7 @@ describe('LocationHtml5Url', function() {
|
|||
upgradeModule.$injector = {get: injectorFactory()};
|
||||
});
|
||||
|
||||
beforeEach(
|
||||
inject([LocationUpgradeService], (loc: LocationUpgradeService) => { $location = loc; }));
|
||||
beforeEach(inject([$locationShim], (loc: $locationShim) => { $location = loc; }));
|
||||
|
||||
|
||||
it('should set the URL', () => {
|
||||
|
@ -166,7 +164,7 @@ describe('LocationHtml5Url', function() {
|
|||
|
||||
|
||||
describe('NewUrl', function() {
|
||||
let $location: LocationUpgradeService;
|
||||
let $location: $locationShim;
|
||||
let upgradeModule: UpgradeModule;
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -182,8 +180,7 @@ describe('NewUrl', function() {
|
|||
upgradeModule.$injector = {get: injectorFactory()};
|
||||
});
|
||||
|
||||
beforeEach(
|
||||
inject([LocationUpgradeService], (loc: LocationUpgradeService) => { $location = loc; }));
|
||||
beforeEach(inject([$locationShim], (loc: $locationShim) => { $location = loc; }));
|
||||
|
||||
// Sets the default most of these tests rely on
|
||||
function setupUrl(url = '/path/b?search=a&b=c&d#hash') { $location.url(url); }
|
||||
|
@ -472,7 +469,7 @@ describe('NewUrl', function() {
|
|||
});
|
||||
|
||||
describe('New URL Parsing', () => {
|
||||
let $location: LocationUpgradeService;
|
||||
let $location: $locationShim;
|
||||
let upgradeModule: UpgradeModule;
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -489,8 +486,7 @@ describe('New URL Parsing', () => {
|
|||
upgradeModule.$injector = {get: injectorFactory()};
|
||||
});
|
||||
|
||||
beforeEach(
|
||||
inject([LocationUpgradeService], (loc: LocationUpgradeService) => { $location = loc; }));
|
||||
beforeEach(inject([$locationShim], (loc: $locationShim) => { $location = loc; }));
|
||||
|
||||
it('should prepend path with basePath', function() {
|
||||
$location.$$parse('http://server/base/abc?a');
|
||||
|
@ -504,7 +500,7 @@ describe('New URL Parsing', () => {
|
|||
});
|
||||
|
||||
describe('New URL Parsing', () => {
|
||||
let $location: LocationUpgradeService;
|
||||
let $location: $locationShim;
|
||||
let upgradeModule: UpgradeModule;
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -520,8 +516,7 @@ describe('New URL Parsing', () => {
|
|||
upgradeModule.$injector = {get: injectorFactory()};
|
||||
});
|
||||
|
||||
beforeEach(
|
||||
inject([LocationUpgradeService], (loc: LocationUpgradeService) => { $location = loc; }));
|
||||
beforeEach(inject([$locationShim], (loc: $locationShim) => { $location = loc; }));
|
||||
|
||||
it('should parse new url', function() {
|
||||
$location.$$parse('http://host.com/base');
|
||||
|
@ -629,7 +624,7 @@ describe('New URL Parsing', () => {
|
|||
});
|
||||
});
|
||||
|
||||
function parseLinkAndReturn(location: LocationUpgradeService, toUrl: string, relHref?: string) {
|
||||
function parseLinkAndReturn(location: $locationShim, toUrl: string, relHref?: string) {
|
||||
const resetUrl = location.$$parseLinkUrl(toUrl, relHref);
|
||||
return resetUrl && location.absUrl() || undefined;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import {MockPlatformLocation} from '@angular/common/testing';
|
|||
import {Inject, InjectionToken, ModuleWithProviders, NgModule, Optional} from '@angular/core';
|
||||
import {UpgradeModule} from '@angular/upgrade/static';
|
||||
|
||||
import {LocationUpgradeProvider, LocationUpgradeService} from '../src/$location';
|
||||
import {$locationShim, $locationShimProvider} from '../src/$location_shim';
|
||||
import {LocationUpgradeModule} from '../src/location_upgrade_module';
|
||||
import {UrlCodec} from '../src/params';
|
||||
|
||||
|
@ -60,7 +60,7 @@ export class LocationUpgradeTestModule {
|
|||
deps: [[new Inject(APP_BASE_HREF), new Optional()]]
|
||||
},
|
||||
{
|
||||
provide: LocationUpgradeService,
|
||||
provide: $locationShim,
|
||||
useFactory: provide$location,
|
||||
deps: [
|
||||
UpgradeModule, Location, PlatformLocation, UrlCodec, LocationStrategy,
|
||||
|
@ -81,8 +81,8 @@ export class LocationUpgradeTestModule {
|
|||
export function provide$location(
|
||||
ngUpgrade: UpgradeModule, location: Location, platformLocation: PlatformLocation,
|
||||
urlCodec: UrlCodec, locationStrategy: LocationStrategy, config?: LocationUpgradeTestingConfig) {
|
||||
const $locationProvider = new LocationUpgradeProvider(
|
||||
ngUpgrade, location, platformLocation, urlCodec, locationStrategy);
|
||||
const $locationProvider =
|
||||
new $locationShimProvider(ngUpgrade, location, platformLocation, urlCodec, locationStrategy);
|
||||
|
||||
$locationProvider.hashPrefix(config && config.hashPrefix);
|
||||
$locationProvider.html5Mode(config && !config.useHash);
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
],
|
||||
"@angular/platform-browser": [
|
||||
"../../../dist/packages/platform-browser"
|
||||
],
|
||||
"@angular/upgrade/static": [
|
||||
"../../../dist/packages/upgrade/static"
|
||||
]
|
||||
},
|
||||
"outDir": "../../../dist/packages/common"
|
||||
|
|
|
@ -1,4 +1,37 @@
|
|||
export declare const $locationProvider: Function;
|
||||
export declare class $locationShim {
|
||||
constructor($injector: any, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy);
|
||||
$$parse(url: string): void;
|
||||
$$parseLinkUrl(url: string, relHref?: string | null): boolean;
|
||||
absUrl(): string;
|
||||
hash(hash: string | number | null): this;
|
||||
hash(): string;
|
||||
host(): string;
|
||||
path(): string;
|
||||
path(path: string | number | null): this;
|
||||
port(): number | null;
|
||||
protocol(): string;
|
||||
replace(): this;
|
||||
search(): {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
search(search: string | number | {
|
||||
[key: string]: unknown;
|
||||
}): this;
|
||||
search(search: string | number | {
|
||||
[key: string]: unknown;
|
||||
}, paramValue: null | undefined | string | number | boolean | string[]): this;
|
||||
state(state: unknown): this;
|
||||
state(): unknown;
|
||||
url(): string;
|
||||
url(url: string): this;
|
||||
}
|
||||
|
||||
export declare class $locationShimProvider {
|
||||
constructor(ngUpgrade: UpgradeModule, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy);
|
||||
$get(): $locationShim;
|
||||
hashPrefix(prefix?: string): void;
|
||||
html5Mode(mode?: any): void;
|
||||
}
|
||||
|
||||
export declare class AngularJSUrlCodec implements UrlCodec {
|
||||
areEqual(a: string, b: string): boolean;
|
||||
|
@ -30,8 +63,6 @@ export declare class AngularJSUrlCodec implements UrlCodec {
|
|||
|
||||
export declare const LOCATION_UPGRADE_CONFIGURATION: InjectionToken<LocationUpgradeConfig>;
|
||||
|
||||
export declare const LOCATION_UPGRADE_MODULE = "LOCATION_UPGRADE_MODULE";
|
||||
|
||||
export interface LocationUpgradeConfig {
|
||||
appBaseHref?: string;
|
||||
hashPrefix?: string;
|
||||
|
@ -44,41 +75,6 @@ export declare class LocationUpgradeModule {
|
|||
static config(config?: LocationUpgradeConfig): ModuleWithProviders<LocationUpgradeModule>;
|
||||
}
|
||||
|
||||
export declare class LocationUpgradeProvider {
|
||||
constructor(ngUpgrade: UpgradeModule, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy);
|
||||
$get(): LocationUpgradeService;
|
||||
hashPrefix(prefix?: string): void;
|
||||
html5Mode(mode?: any): void;
|
||||
}
|
||||
|
||||
export declare class LocationUpgradeService {
|
||||
constructor($injector: any, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy);
|
||||
$$parse(url: string): void;
|
||||
$$parseLinkUrl(url: string, relHref?: string | null): boolean;
|
||||
absUrl(): string;
|
||||
hash(hash: string | number | null): this;
|
||||
hash(): string;
|
||||
host(): string;
|
||||
path(): string;
|
||||
path(path: string | number | null): this;
|
||||
port(): number | null;
|
||||
protocol(): string;
|
||||
replace(): this;
|
||||
search(): {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
search(search: string | number | {
|
||||
[key: string]: unknown;
|
||||
}): this;
|
||||
search(search: string | number | {
|
||||
[key: string]: unknown;
|
||||
}, paramValue: null | undefined | string | number | boolean | string[]): this;
|
||||
state(state: unknown): this;
|
||||
state(): unknown;
|
||||
url(): string;
|
||||
url(url: string): this;
|
||||
}
|
||||
|
||||
export declare abstract class UrlCodec {
|
||||
abstract areEqual(a: string, b: string): boolean;
|
||||
abstract decodeHash(hash: string): string;
|
||||
|
|
Loading…
Reference in New Issue