Skip to content

Commit 8f29351

Browse files
author
Alain BOUDARD
committed
fix: styles and store
1 parent 8918aa0 commit 8f29351

File tree

14 files changed

+171
-16
lines changed

14 files changed

+171
-16
lines changed

application/ng-shell/src/app/app-routing.module.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { NgModule } from '@angular/core';
22
import { RouterModule, Routes } from '@angular/router';
3+
import { HomeComponent } from './home/home.component';
34

45
export const APP_ROUTES: Routes = [
6+
{
7+
path: 'home', component: HomeComponent
8+
},
59
{
610
path: 'users', loadChildren: () => import('./users/users.module').then(m => m.UsersModule)
11+
},
12+
{
13+
path: '', redirectTo: 'home', pathMatch: 'full'
714
}
815
];
916

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
<h1>{{title}}</h1>
21
<ul>
3-
<li class="user">## {{(user$ | async)?.name}} ##</li>
4-
<li><a routerLink="/">Home</a></li>
5-
<li><a routerLink="users">Users</a></li>
2+
<li><span class="title">
3+
{{title}} -
4+
</span></li>
5+
<li><a routerLink="home" routerLinkActive="active">Home</a></li>
6+
<li><a routerLink="users" routerLinkActive="active">Users</a></li>
67
<li *ngFor="let remote of remotes">
7-
<a [routerLink]="remote.routePath">{{remote.displayName}}</a>
8+
<a [routerLink]="remote.routePath" routerLinkActive="active">{{remote.displayName}}</a>
89
</li>
10+
<li class="user"><span>## {{ (user$ | async)?.name }} ##</span></li>
911
</ul>
12+
<main>
1013
<router-outlet></router-outlet>
14+
</main>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
li.user {
1+
li.user > span {
22
color: crimson;
33
}

application/ng-shell/src/app/app.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { HttpClientModule } from '@angular/common/http';
22
import { NgModule } from '@angular/core';
3+
import { FormsModule } from '@angular/forms';
34
import { BrowserModule } from '@angular/platform-browser';
45
import { CoreModule } from 'core';
56

@@ -8,13 +9,16 @@ import { AppComponent } from './app.component';
89
import { StoreModule } from '@ngrx/store';
910
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
1011
import { environment } from '../environments/environment';
12+
import { HomeComponent } from './home/home.component';
1113
import { reducers, metaReducers } from './store';
1214

1315
@NgModule({
1416
declarations: [
15-
AppComponent
17+
AppComponent,
18+
HomeComponent
1619
],
1720
imports: [
21+
FormsModule,
1822
BrowserModule,
1923
HttpClientModule,
2024
AppRoutingModule,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { Store } from '@ngrx/store';
3+
import { CoreService } from 'core';
4+
import { Observable } from 'rxjs';
5+
import { getCount } from '../store/counter.selectors';
6+
7+
@Component({
8+
selector: 'app-home',
9+
template: `
10+
<h2>home works !</h2>
11+
<p>This is the counter: {{counter$ | async}}</p>
12+
<p><button class="btn" (click)="getCore()">get core</button></p>
13+
<div>
14+
<input type="number" [(ngModel)]="a"> / <input type="number" [(ngModel)]="b">
15+
</div>
16+
<div>
17+
<span>
18+
val : {{a + b}}
19+
</span>
20+
</div>
21+
22+
`,
23+
styles: []
24+
})
25+
export class HomeComponent {
26+
27+
28+
counter$: Observable<number> = this.store.select(getCount);
29+
30+
a = 1;
31+
b = 2;
32+
33+
getCore(): void {
34+
alert(this.coreService.getCore());
35+
}
36+
37+
constructor(
38+
private store: Store,
39+
private coreService: CoreService
40+
) {
41+
}
42+
43+
44+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createAction, props } from '@ngrx/store';
2+
3+
export const loadCounters = createAction(
4+
'[Counter] Load Counters'
5+
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Action, createReducer, on } from '@ngrx/store';
2+
3+
4+
export const counterFeatureKey = 'counter';
5+
6+
export interface CounterState {
7+
count: number;
8+
}
9+
10+
export const initialState: CounterState = {
11+
count: 10
12+
};
13+
14+
export const reducer = createReducer(
15+
initialState,
16+
17+
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createFeatureSelector, createSelector } from '@ngrx/store';
2+
import { CounterState, counterFeatureKey } from './counter.reducer';
3+
4+
const getCounterState = createFeatureSelector<CounterState>(counterFeatureKey);
5+
6+
export const getCount = createSelector(
7+
getCounterState,
8+
state => state.count
9+
);

application/ng-shell/src/app/store/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import {
66
MetaReducer
77
} from '@ngrx/store';
88
import { environment } from '../../environments/environment';
9-
9+
import * as fromCounter from './counter.reducer';
1010

1111
export interface State {
12-
12+
[fromCounter.counterFeatureKey]: fromCounter.CounterState;
1313
}
1414

1515
export const reducers: ActionReducerMap<State> = {
16-
16+
[fromCounter.counterFeatureKey]: fromCounter.reducer,
1717
};
1818

1919

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<p>users works!</p>
1+
<h2>users works !</h2>
2+
<p>This is the internal feature</p>

0 commit comments

Comments
 (0)