Skip to content

Commit c46e777

Browse files
authored
docs: add inline docs (#277)
# Documentation - Improve descriptions and example labels in the readme file - Add inline docs to public API
1 parent 54c2233 commit c46e777

File tree

5 files changed

+184
-8
lines changed

5 files changed

+184
-8
lines changed

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ A `RouterStore` service has the following public properties:
2828
| routeParams$: Observable<Params> | Select the current route parameters. |
2929
| url$: Observable<string> | Select the current URL. |
3030
| selectQueryParam<TValue>(param: string): Observable<TValue> | Select the specified query parameter. |
31-
| selectRouteParam<TValue>(param: string): Observable<TValue> | Select the specified route paramter. |
31+
| selectRouteParam<TValue>(param: string): Observable<TValue> | Select the specified route parameter. |
3232

3333
A `RouterStore` service is provided by using either `provideGlobalRouterStore` or `provideLocalRouterStore`.
3434

@@ -40,10 +40,22 @@ other component-level services.
4040

4141
### Global router store
4242

43-
An application-wide router store. Can be injected in any class. Provide
44-
in a root environment injector by using `provideGlobalRouterStore`.
43+
An application-wide router store that can be injected in any class. Use
44+
`provideGlobalRouterStore` to provide it in a root environment injector.
4545

46-
Usage:
46+
Providing in a standalone Angular application:
47+
48+
```typescript
49+
// main.ts
50+
// (...)
51+
import { provideGlobalRouterStore } from '@ngworker/router-component-store';
52+
53+
bootstrapApplication(AppComponent, {
54+
providers: [provideGlobalRouterStore()],
55+
}).catch((error) => console.error(error));
56+
```
57+
58+
Providing in a classic Angular application:
4759

4860
```typescript
4961
// app.module.ts
@@ -57,6 +69,8 @@ import { provideGlobalRouterStore } from '@ngworker/router-component-store';
5769
export class AppModule {}
5870
```
5971

72+
Usage in service:
73+
6074
```typescript
6175
// hero.service.ts
6276
// (...)
@@ -66,12 +80,14 @@ import { RouterStore } from '@ngworker/router-component-store';
6680
providedIn: 'root',
6781
})
6882
export class HeroService {
69-
activeHeroId$: Observable<string> = this.routerStore.selectQueryParam('id');
83+
activeHeroId$: Observable<string> = this.routerStore.selectRouteParam('id');
7084

7185
constructor(private routerStore: RouterStore) {}
7286
}
7387
```
7488

89+
Usage in component:
90+
7591
```typescript
7692
// hero-detail.component.ts
7793
// (...)
@@ -81,7 +97,7 @@ import { RouterStore } from '@ngworker/router-component-store';
8197
// (...)
8298
})
8399
export class HeroDetailComponent {
84-
heroId$: Observable<string> = this.routerStore.selectQueryParam('id');
100+
heroId$: Observable<string> = this.routerStore.selectRouteParam('id');
85101

86102
constructor(private routerStore: RouterStore) {}
87103
}
@@ -93,7 +109,7 @@ A component-level router store. Can be injected in any directive, component,
93109
pipe, or component-level service. Explicitly provided in a component sub-tree
94110
using `Component.providers` or `Component.viewProviders`.
95111

96-
Usage:
112+
Usage in component:
97113

98114
```typescript
99115
// hero-detail.component.ts
@@ -108,7 +124,7 @@ import {
108124
providers: [provideLocalRouterStore()],
109125
})
110126
export class HeroDetailComponent {
111-
heroId$: Observable<string> = this.routerStore.selectQueryParam('id');
127+
heroId$: Observable<string> = this.routerStore.selectRouteParam('id');
112128

113129
constructor(private routerStore: RouterStore) {}
114130
}

packages/router-component-store/src/lib/@ngrx/router-store/minimal_serializer.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,57 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
* SOFTWARE.
2424
*/
25+
/**
26+
* @license
27+
* Copyright Google LLC All Rights Reserved.
28+
*
29+
* Use of this source code is governed by an MIT-style license that can be
30+
* found in the LICENSE file at https://angular.io/license
31+
*/
2532
import { Injectable } from '@angular/core';
2633
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
2734

35+
/**
36+
* Contains the information about a route associated with a component loaded in
37+
* an outlet at a particular moment in time. MinimalActivatedRouteSnapshot can
38+
* also be used to traverse the router state tree.
39+
*/
2840
export interface MinimalActivatedRouteSnapshot {
41+
/**
42+
* The configuration used to match this route.
43+
*/
2944
readonly routeConfig: ActivatedRouteSnapshot['routeConfig'];
45+
/**
46+
* The URL segments matched by this route.
47+
*/
3048
readonly url: ActivatedRouteSnapshot['url'];
49+
/**
50+
* The matrix parameters scoped to this route.
51+
*/
3152
readonly params: ActivatedRouteSnapshot['params'];
53+
/**
54+
* The query parameters shared by all the routes.
55+
*/
3256
readonly queryParams: ActivatedRouteSnapshot['queryParams'];
57+
/**
58+
* The URL fragment shared by all the routes.
59+
*/
3360
readonly fragment: ActivatedRouteSnapshot['fragment'];
61+
/**
62+
* The static and resolved data of this route.
63+
*/
3464
readonly data: ActivatedRouteSnapshot['data'];
65+
/**
66+
* The outlet name of the route.
67+
*/
3568
readonly outlet: ActivatedRouteSnapshot['outlet'];
69+
/**
70+
* The first child of this route in the router state tree
71+
*/
3672
readonly firstChild?: MinimalActivatedRouteSnapshot;
73+
/**
74+
* The children of this route in the router state tree.
75+
*/
3776
readonly children: MinimalActivatedRouteSnapshot[];
3877
}
3978

packages/router-component-store/src/lib/global-router-store/provide-global-router-store.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@ import { ClassProvider, Provider } from '@angular/core';
22
import { RouterStore } from '../router-store';
33
import { GlobalRouterStore } from './global-router-store';
44

5+
/**
6+
* Provide an application-wide router store that can be injected in any class.
7+
*
8+
* Use this provider factory in a root environment injector.
9+
*
10+
* @returns The providers required for a global router store.
11+
*
12+
* @example
13+
* // Providing in a standalone Angular application
14+
* // main.ts
15+
* // (...)
16+
* import { provideGlobalRouterStore } from '@ngworker/router-component-store';
17+
*
18+
* bootstrapApplication(AppComponent, {
19+
* providers: [provideGlobalRouterStore()],
20+
* }).catch((error) => console.error(error));
21+
*
22+
*
23+
* @example
24+
* // Providing in a classic Angular application
25+
* // app.module.ts
26+
* // (...)
27+
* import { provideGlobalRouterStore } from '@ngworker/router-component-store';
28+
*
29+
* (@)NgModule({
30+
* // (...)
31+
* providers: [provideGlobalRouterStore()],
32+
* })
33+
* export class AppModule {}
34+
*/
535
export function provideGlobalRouterStore(): Provider {
636
const globalRouterStoreProvider: ClassProvider = {
737
provide: RouterStore,

packages/router-component-store/src/lib/local-router-store/provide-local-router-store.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@ import { ClassProvider, Provider } from '@angular/core';
22
import { RouterStore } from '../router-store';
33
import { LocalRouterStore } from './local-router-store';
44

5+
/**
6+
* Provide a component-level router store that can be injected in any directive,
7+
* component, pipe, or component-level service.
8+
*
9+
* Use this provider factory in `Component.providers` or
10+
* `Component.viewProviders` to make a local router store available to a
11+
* component sub-tree.
12+
*
13+
* @returns The providers required for a local router store.
14+
*
15+
* @example
16+
* // Providing and injecting in a component
17+
* // hero-detail.component.ts
18+
* // (...)
19+
* import {
20+
* provideLocalRouterStore,
21+
* RouterStore,
22+
* } from '@ngworker/router-component-store';
23+
*
24+
* (@)Component({
25+
* // (...)
26+
* providers: [provideLocalRouterStore()],
27+
* })
28+
* export class HeroDetailComponent {
29+
* heroId$: Observable<string> = this.routerStore.selectQueryParam('id');
30+
*
31+
* constructor(private routerStore: RouterStore) {}
32+
* }
33+
*/
534
export function provideLocalRouterStore(): Provider {
635
const localRouterStoreProvider: ClassProvider = {
736
provide: RouterStore,

packages/router-component-store/src/lib/router-store.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,76 @@ import { Data, Params } from '@angular/router';
33
import { Observable } from 'rxjs';
44
import { MinimalActivatedRouteSnapshot } from './@ngrx/router-store/minimal_serializer';
55

6+
/**
7+
* An Angular Router-connecting NgRx component store.
8+
*
9+
* A `RouterStore` service is provided by using either
10+
* `provideGlobalRouterStore` or `provideLocalRouterStore`.
11+
*
12+
* The _global_ `RouterStore` service is provided in a root environment injector
13+
* and is never destroyed but can be injected in any class.
14+
*
15+
* A _local_ `RouterStore` requires a component-level provider, follows the
16+
* lifecycle of that component, and can be injected in declarables as well as
17+
* other component-level services.
18+
*
19+
* @example
20+
* // Usage in a component
21+
* // hero-detail.component.ts
22+
* // (...)
23+
* import { RouterStore } from '@ngworker/router-component-store';
24+
*
25+
* (@)Component({
26+
* // (...)
27+
* })
28+
* export class HeroDetailComponent {
29+
* heroId$: Observable<string> = this.routerStore.selectRouteParam('id');
30+
*
31+
* constructor(private routerStore: RouterStore) {}
32+
* }
33+
*/
634
@Injectable()
735
export abstract class RouterStore {
36+
/**
37+
* Select the current route.
38+
*/
839
abstract readonly currentRoute$: Observable<MinimalActivatedRouteSnapshot>;
40+
/**
41+
* Select the current route fragment.
42+
*/
943
abstract readonly fragment$: Observable<string | null>;
44+
/**
45+
* Select the current route query parameters.
46+
*/
1047
abstract readonly queryParams$: Observable<Params>;
48+
/**
49+
* Select the current route data.
50+
*/
1151
abstract readonly routeData$: Observable<Data>;
52+
/**
53+
* Select the current route parameters.
54+
*/
1255
abstract readonly routeParams$: Observable<Params>;
56+
/**
57+
* Select the current URL.
58+
*/
1359
abstract readonly url$: Observable<string>;
60+
/**
61+
* Select the specified query parameter.
62+
*
63+
* @param param The name of the query parameter.
64+
*
65+
* @example <caption>Usage</caption>
66+
* const order$ = routerStore.selectQueryParam('order');
67+
*/
1468
abstract selectQueryParam<TValue>(param: string): Observable<TValue>;
69+
/**
70+
* Select the specified route parameter.
71+
*
72+
* @param param The name of the route parameter.
73+
*
74+
* @example <caption>Usage</caption>
75+
* const id$ = routerStore.selectRouteParam('id');
76+
*/
1577
abstract selectRouteParam<TValue>(param: string): Observable<TValue>;
1678
}

0 commit comments

Comments
 (0)