Skip to content

Commit 0d52a27

Browse files
brandonrobertsjasonaden
authored andcommitted
docs(common): update API docs for unified location service for upgrading (angular#30567)
PR Close angular#30567
1 parent 697046c commit 0d52a27

File tree

3 files changed

+130
-57
lines changed

3 files changed

+130
-57
lines changed

packages/common/upgrade/src/location_shim.ts

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ const DEFAULT_PORTS: {[key: string]: number} = {
2222
};
2323

2424
/**
25-
* Docs TBD.
25+
* Location service that provides a drop-in replacement for the $location service
26+
* provided in AngularJS.
27+
*
28+
* @see [Using the Angular Unified Location Service](guide/upgrade#using-the-unified-angular-location-service)
2629
*
2730
* @publicApi
2831
*/
@@ -321,12 +324,17 @@ export class $locationShim {
321324
}
322325

323326
/**
324-
* Register URL change listeners. This API can be used to catch updates performed by the
325-
* AngularJS framework. These changes are a subset of the `$locationChangeStart/Success` events
326-
* as those events fire when AngularJS updates it's internally referenced version of the browser
327-
* URL. It's possible for `$locationChange` events to happen, but for the browser URL
327+
* Registers listeners for URL changes. This API is used to catch updates performed by the
328+
* AngularJS framework. These changes are a subset of the `$locationChangeStart` and
329+
* `$locationChangeSuccess` events which fire when AngularJS updates its internally-referenced
330+
* version of the browser URL.
331+
*
332+
* It's possible for `$locationChange` events to happen, but for the browser URL
328333
* (window.location) to remain unchanged. This `onChange` callback will fire only when AngularJS
329334
* actually updates the browser URL (window.location).
335+
*
336+
* @param fn The callback function that is triggered for the listener when the URL changes.
337+
* @param err The callback function that is triggered when an error occurs.
330338
*/
331339
onChange(
332340
fn: (url: string, state: unknown, oldUrl: string, oldState: unknown) => void,
@@ -346,6 +354,11 @@ export class $locationShim {
346354
});
347355
}
348356

357+
/**
358+
* Parses the provided URL, and sets the current URL to the parsed result.
359+
*
360+
* @param url The URL string.
361+
*/
349362
$$parse(url: string) {
350363
let pathUrl: string|undefined;
351364
if (url.startsWith('/')) {
@@ -366,6 +379,12 @@ export class $locationShim {
366379
this.composeUrls();
367380
}
368381

382+
/**
383+
* Parses the provided URL and its relative URL.
384+
*
385+
* @param url The full URL string.
386+
* @param relHref A URL string relative to the full URL string.
387+
*/
369388
$$parseLinkUrl(url: string, relHref?: string|null): boolean {
370389
// When relHref is passed, it should be a hash and is handled separately
371390
if (relHref && relHref[0] === '#') {
@@ -413,9 +432,8 @@ export class $locationShim {
413432
}
414433

415434
/**
416-
* This method is getter only.
417-
*
418-
* Return full URL representation with all segments encoded according to rules specified in
435+
* Retrieves the full URL representation with all segments encoded according to
436+
* rules specified in
419437
* [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt).
420438
*
421439
*
@@ -428,12 +446,8 @@ export class $locationShim {
428446
absUrl(): string { return this.$$absUrl; }
429447

430448
/**
431-
* This method is getter / setter.
432-
*
433-
* Return URL (e.g. `/path?a=b#hash`) when called without any parameter.
434-
*
435-
* Change path, search and hash, when called with parameter and return `$location`.
436-
*
449+
* Retrieves the current URL, or sets a new URL. When setting a URL,
450+
* changes the path, search, and hash, and returns a reference to its own instance.
437451
*
438452
* ```js
439453
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
@@ -463,10 +477,7 @@ export class $locationShim {
463477
}
464478

465479
/**
466-
* This method is getter only.
467-
*
468-
* Return protocol of current URL.
469-
*
480+
* Retrieves the protocol of the current URL.
470481
*
471482
* ```js
472483
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
@@ -477,11 +488,9 @@ export class $locationShim {
477488
protocol(): string { return this.$$protocol; }
478489

479490
/**
480-
* This method is getter only.
491+
* Retrieves the protocol of the current URL.
481492
*
482-
* Return host of current URL.
483-
*
484-
* Note: compared to the non-AngularJS version `location.host` which returns `hostname:port`, this
493+
* In contrast to the non-AngularJS version `location.host` which returns `hostname:port`, this
485494
* returns the `hostname` portion only.
486495
*
487496
*
@@ -500,10 +509,7 @@ export class $locationShim {
500509
host(): string { return this.$$host; }
501510

502511
/**
503-
* This method is getter only.
504-
*
505-
* Return port of current URL.
506-
*
512+
* Retrieves the port of the current URL.
507513
*
508514
* ```js
509515
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
@@ -514,16 +520,12 @@ export class $locationShim {
514520
port(): number|null { return this.$$port; }
515521

516522
/**
517-
* This method is getter / setter.
518-
*
519-
* Return path of current URL when called without any parameter.
523+
* Retrieves the path of the current URL, or changes the path and returns a reference to its own
524+
* instance.
520525
*
521-
* Change path when called with parameter and return `$location`.
522-
*
523-
* Note: Path should always begin with forward slash (/), this method will add the forward slash
526+
* Paths should always begin with forward slash (/). This method adds the forward slash
524527
* if it is missing.
525528
*
526-
*
527529
* ```js
528530
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
529531
* let path = $location.path();
@@ -548,11 +550,8 @@ export class $locationShim {
548550
}
549551

550552
/**
551-
* This method is getter / setter.
552-
*
553-
* Return search part (as object) of current URL when called without any parameter.
554-
*
555-
* Change search part when called with parameter and return `$location`.
553+
* Retrieves a map of the search parameters of the current URL, or changes a search
554+
* part and returns a reference to its own instance.
556555
*
557556
*
558557
* ```js
@@ -585,8 +584,7 @@ export class $locationShim {
585584
* If `paramValue` is `true`, the property specified via the first argument will be added with no
586585
* value nor trailing equal sign.
587586
*
588-
* @return {Object} If called with no arguments returns the parsed `search` object. If called with
589-
* one or more arguments returns `$location` object itself.
587+
* @return {Object} The parsed `search` object of the current URL, or the changed `search` object.
590588
*/
591589
search(): {[key: string]: unknown};
592590
search(search: string|number|{[key: string]: unknown}): this;
@@ -633,12 +631,8 @@ export class $locationShim {
633631
}
634632

635633
/**
636-
* This method is getter / setter.
637-
*
638-
* Returns the hash fragment when called without any parameters.
639-
*
640-
* Changes the hash fragment when called with a parameter and returns `$location`.
641-
*
634+
* Retrieves the current hash fragment, or changes the hash fragment and returns a reference to
635+
* its own instance.
642636
*
643637
* ```js
644638
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
@@ -660,7 +654,7 @@ export class $locationShim {
660654
}
661655

662656
/**
663-
* If called, all changes to $location during the current `$digest` will replace the current
657+
* Changes to `$location` during the current `$digest` will replace the current
664658
* history record, instead of adding a new one.
665659
*/
666660
replace(): this {
@@ -669,15 +663,13 @@ export class $locationShim {
669663
}
670664

671665
/**
672-
* This method is getter / setter.
673-
*
674-
* Return the history state object when called without any parameter.
666+
* Retrieves the history state object when called without any parameter.
675667
*
676668
* Change the history state object when called with one parameter and return `$location`.
677669
* The state object is later passed to `pushState` or `replaceState`.
678670
*
679-
* NOTE: This method is supported only in HTML5 mode and only in browsers supporting
680-
* the HTML5 History API (i.e. methods `pushState` and `replaceState`). If you need to support
671+
* This method is supported only in HTML5 mode and only in browsers supporting
672+
* the HTML5 History API methods such as `pushState` and `replaceState`. If you need to support
681673
* older browsers (like IE9 or Android < 4.0), don't use this method.
682674
*
683675
*/
@@ -694,7 +686,8 @@ export class $locationShim {
694686
}
695687

696688
/**
697-
* Docs TBD.
689+
* The factory function used to create an instance of the `$locationShim` in Angular,
690+
* and provides an API-compatiable `$locationProvider` for AngularJS.
698691
*
699692
* @publicApi
700693
*/
@@ -704,6 +697,9 @@ export class $locationShimProvider {
704697
private platformLocation: PlatformLocation, private urlCodec: UrlCodec,
705698
private locationStrategy: LocationStrategy) {}
706699

700+
/**
701+
* Factory method that returns an instance of the $locationShim
702+
*/
707703
$get() {
708704
return new $locationShim(
709705
this.ngUpgrade.$injector, this.location, this.platformLocation, this.urlCodec,

packages/common/upgrade/src/location_upgrade_module.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,31 @@ import {AngularJSUrlCodec, UrlCodec} from './params';
2020
* @publicApi
2121
*/
2222
export interface LocationUpgradeConfig {
23+
/**
24+
* Configures whether the location upgrade module should use the `HashLocationStrategy`
25+
* or the `PathLocationStrategy`
26+
*/
2327
useHash?: boolean;
28+
/**
29+
* Configures the hash prefix used in the URL when using the `HashLocationStrategy`
30+
*/
2431
hashPrefix?: string;
32+
/**
33+
* Configures the URL codec for encoding and decoding URLs. Default is the `AngularJSCodec`
34+
*/
2535
urlCodec?: typeof UrlCodec;
36+
/**
37+
* Configures the base href when used in server-side rendered applications
38+
*/
2639
serverBaseHref?: string;
40+
/**
41+
* Configures the base href when used in client-side rendered applications
42+
*/
2743
appBaseHref?: string;
2844
}
2945

3046
/**
31-
* Is used in DI to configure the location upgrade package.
47+
* A provider token used to configure the location upgrade module.
3248
*
3349
* @publicApi
3450
*/
@@ -38,7 +54,9 @@ export const LOCATION_UPGRADE_CONFIGURATION =
3854
const APP_BASE_HREF_RESOLVED = new InjectionToken<string>('APP_BASE_HREF_RESOLVED');
3955

4056
/**
41-
* Module used for configuring Angular's LocationUpgradeService.
57+
* `NgModule` used for providing and configuring Angular's Unified Location Service for upgrading.
58+
*
59+
* @see [Using the Unified Angular Location Service](guide/upgrade#using-the-unified-angular-location-service)
4260
*
4361
* @publicApi
4462
*/

packages/common/upgrade/src/params.ts

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,80 @@
1212
* @publicApi
1313
**/
1414
export abstract class UrlCodec {
15+
/**
16+
* Encodes the path from the provided string
17+
*
18+
* @param path The path string
19+
*/
1520
abstract encodePath(path: string): string;
21+
22+
/**
23+
* Decodes the path from the provided string
24+
*
25+
* @param path The path string
26+
*/
1627
abstract decodePath(path: string): string;
1728

29+
/**
30+
* Encodes the search string from the provided string or object
31+
*
32+
* @param path The path string or object
33+
*/
1834
abstract encodeSearch(search: string|{[k: string]: unknown}): string;
35+
36+
/**
37+
* Decodes the search objects from the provided string
38+
*
39+
* @param path The path string
40+
*/
1941
abstract decodeSearch(search: string): {[k: string]: unknown};
2042

43+
/**
44+
* Encodes the hash from the provided string
45+
*
46+
* @param path The hash string
47+
*/
2148
abstract encodeHash(hash: string): string;
49+
50+
/**
51+
* Decodes the hash from the provided string
52+
*
53+
* @param path The hash string
54+
*/
2255
abstract decodeHash(hash: string): string;
2356

57+
/**
58+
* Normalizes the URL from the provided string
59+
*
60+
* @param path The URL string
61+
*/
2462
abstract normalize(href: string): string;
63+
64+
65+
/**
66+
* Normalizes the URL from the provided string, search, hash, and base URL parameters
67+
*
68+
* @param path The URL path
69+
* @param search The search object
70+
* @param hash The has string
71+
* @param baseUrl The base URL for the URL
72+
*/
2573
abstract normalize(path: string, search: {[k: string]: unknown}, hash: string, baseUrl?: string):
2674
string;
2775

76+
/**
77+
* Checks whether the two strings are equal
78+
* @param valA First string for comparison
79+
* @param valB Second string for comparison
80+
*/
2881
abstract areEqual(valA: string, valB: string): boolean;
2982

83+
/**
84+
* Parses the URL string based on the base URL
85+
*
86+
* @param url The full URL string
87+
* @param base The base for the URL
88+
*/
3089
abstract parse(url: string, base?: string): {
3190
href: string,
3291
protocol: string,
@@ -40,8 +99,8 @@ export abstract class UrlCodec {
4099
}
41100

42101
/**
43-
* A `AngularJSUrlCodec` that uses logic from AngularJS to serialize and parse URLs
44-
* and URL parameters
102+
* A `UrlCodec` that uses logic from AngularJS to serialize and parse URLs
103+
* and URL parameters.
45104
*
46105
* @publicApi
47106
*/

0 commit comments

Comments
 (0)