Skip to content

Commit 75f57f0

Browse files
authored
refactor: ensure ECMAScript compliance (#286)
# Refactors - Remove constructor parameter properties for ECMAScript compatibility - Remove constructor parameter decorators for ECMAScript compatibility
1 parent 63eb967 commit 75f57f0

File tree

8 files changed

+31
-35
lines changed

8 files changed

+31
-35
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ import { RouterStore } from '@ngworker/router-component-store';
8080
providedIn: 'root',
8181
})
8282
export class HeroService {
83-
activeHeroId$: Observable<string> = this.routerStore.selectRouteParam('id');
83+
#routerStore = inject(RouterStore);
8484

85-
constructor(private routerStore: RouterStore) {}
85+
activeHeroId$: Observable<string | undefined> =
86+
this.#routerStore.selectRouteParam('id');
8687
}
8788
```
8889

@@ -97,9 +98,10 @@ import { RouterStore } from '@ngworker/router-component-store';
9798
// (...)
9899
})
99100
export class HeroDetailComponent {
100-
heroId$: Observable<string> = this.routerStore.selectRouteParam('id');
101+
#routerStore = inject(RouterStore);
101102

102-
constructor(private routerStore: RouterStore) {}
103+
heroId$: Observable<string | undefined> =
104+
this.#routerStore.selectRouteParam('id');
103105
}
104106
```
105107

@@ -124,8 +126,9 @@ import {
124126
providers: [provideLocalRouterStore()],
125127
})
126128
export class HeroDetailComponent {
127-
heroId$: Observable<string> = this.routerStore.selectRouteParam('id');
129+
#routerStore = inject(RouterStore);
128130

129-
constructor(private routerStore: RouterStore) {}
131+
heroId$: Observable<string | undefined> =
132+
this.#routerStore.selectRouteParam('id');
130133
}
131134
```

packages/router-component-store/src/lib/classic-routed-component-test.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommonModule } from '@angular/common';
2-
import { Component, NgModule } from '@angular/core';
2+
import { Component, inject, NgModule } from '@angular/core';
33
import { ComponentFixtureAutoDetect, TestBed } from '@angular/core/testing';
44
import { By } from '@angular/platform-browser';
55
import { Router, RouterModule } from '@angular/router';
@@ -88,13 +88,11 @@ async function setup({
8888
`,
8989
})
9090
class ClassicRoutedComponent {
91-
id$: Observable<string | undefined>;
92-
url$: Observable<string>;
91+
#routerStore = inject(RouterStore);
9392

94-
constructor(routerStore: RouterStore) {
95-
this.id$ = routerStore.selectRouteParam('id');
96-
this.url$ = routerStore.url$;
97-
}
93+
id$: Observable<string | undefined> =
94+
this.#routerStore.selectRouteParam('id');
95+
url$: Observable<string> = this.#routerStore.url$;
9896
}
9997

10098
@NgModule({

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Inject, Injectable } from '@angular/core';
1+
import { Injectable } from '@angular/core';
22
import { Data, Params, Router } from '@angular/router';
33
import { ComponentStore } from '@ngrx/component-store';
44
import { map, Observable } from 'rxjs';
@@ -55,10 +55,7 @@ export class GlobalRouterStore
5555
(routerState) => routerState.url
5656
);
5757

58-
constructor(
59-
@Inject(Router) router: Router,
60-
serializer: MinimalRouterStateSerializer
61-
) {
58+
constructor(router: Router, serializer: MinimalRouterStateSerializer) {
6259
super({
6360
routerState: serializer.serialize(router.routerState.snapshot),
6461
});

packages/router-component-store/src/lib/local-router-store/local-router-store-selectors.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, inject } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { Router, Routes } from '@angular/router';
@@ -18,15 +18,15 @@ class DummyAppComponent {}
1818
viewProviders: [provideLocalRouterStore()],
1919
})
2020
class DummyLoginComponent {
21-
constructor(public store: RouterStore) {}
21+
routerStore = inject(RouterStore);
2222
}
2323

2424
describe(`${LocalRouterStore.name} selectors`, () => {
2525
const getStore = () =>
2626
(
2727
rootFixture.debugElement.query(By.directive(DummyLoginComponent))
2828
.componentInstance as DummyLoginComponent
29-
).store;
29+
).routerStore;
3030

3131
beforeEach(async () => {
3232
const routes: Routes = [

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Inject, Injectable } from '@angular/core';
1+
import { Injectable } from '@angular/core';
22
import { ActivatedRoute, Data, Params, Router } from '@angular/router';
33
import { ComponentStore } from '@ngrx/component-store';
44
import { map, Observable } from 'rxjs';
@@ -46,8 +46,8 @@ export class LocalRouterStore
4646
);
4747

4848
constructor(
49-
@Inject(ActivatedRoute) route: ActivatedRoute,
50-
@Inject(Router) router: Router,
49+
route: ActivatedRoute,
50+
router: Router,
5151
serializer: MinimalRouterStateSerializer
5252
) {
5353
super({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import { LocalRouterStore } from './local-router-store';
2626
* providers: [provideLocalRouterStore()],
2727
* })
2828
* export class HeroDetailComponent {
29-
* heroId$: Observable<string> = this.routerStore.selectQueryParam('id');
29+
* #routerStore = inject(RouterStore);
3030
*
31-
* constructor(private routerStore: RouterStore) {}
31+
* heroId$: Observable<string | undefined> = this.#routerStore.selectQueryParam('id');
3232
* }
3333
*/
3434
export function provideLocalRouterStore(): Provider {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import { MinimalActivatedRouteSnapshot } from './@ngrx/router-store/minimal_seri
2626
* // (...)
2727
* })
2828
* export class HeroDetailComponent {
29-
* heroId$: Observable<string> = this.routerStore.selectRouteParam('id');
29+
* #routerStore = inject(RouterStore);
3030
*
31-
* constructor(private routerStore: RouterStore) {}
31+
* heroId$: Observable<string | undefined> = this.#routerStore.selectRouteParam('id');
3232
* }
3333
*/
3434
@Injectable()

packages/router-component-store/src/lib/standalone-routed-component-test.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommonModule } from '@angular/common';
2-
import { Component } from '@angular/core';
2+
import { Component, inject } from '@angular/core';
33
import { ComponentFixtureAutoDetect, TestBed } from '@angular/core/testing';
44
import { By } from '@angular/platform-browser';
55
import { Router, RouterModule } from '@angular/router';
@@ -87,13 +87,11 @@ async function setup({
8787
`,
8888
})
8989
class StandaloneRoutedComponent {
90-
id$: Observable<string | undefined>;
91-
url$: Observable<string>;
90+
#routerStore = inject(RouterStore);
9291

93-
constructor(routerStore: RouterStore) {
94-
this.id$ = routerStore.selectRouteParam('id');
95-
this.url$ = routerStore.url$;
96-
}
92+
id$: Observable<string | undefined> =
93+
this.#routerStore.selectRouteParam('id');
94+
url$: Observable<string> = this.#routerStore.url$;
9795
}
9896

9997
@Component({

0 commit comments

Comments
 (0)