Skip to content

Commit e384870

Browse files
committed
🚧 refactor for angular 8
1 parent 5c25613 commit e384870

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+876
-825
lines changed

‎angular.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"outputPath": "dist",
1515
"index": "src/index.html",
1616
"main": "src/main.ts",
17-
"tsConfig": "src/tsconfig.app.json",
17+
"tsConfig": "tsconfig.app.json",
1818
"polyfills": "src/polyfills.ts",
1919
"assets": [
2020
"src/assets",
@@ -128,5 +128,8 @@
128128
"@schematics/angular:directive": {
129129
"prefix": "app"
130130
}
131+
},
132+
"cli": {
133+
"defaultCollection": "@ngrx/schematics"
131134
}
132135
}

‎package-lock.json

Lines changed: 31 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@
2020
"@angular/platform-browser": "^8.1.0",
2121
"@angular/platform-browser-dynamic": "^8.1.0",
2222
"@angular/router": "^8.1.0",
23-
"@ngrx/store": "^6.0.0",
24-
"@ngrx/store-devtools": "^6.0.0",
23+
"@ngrx/effects": "^8.0.1",
24+
"@ngrx/entity": "^8.0.1",
25+
"@ngrx/router-store": "^8.0.1",
26+
"@ngrx/schematics": "^8.0.1",
27+
"@ngrx/store": "^8.0.1",
28+
"@ngrx/store-devtools": "^8.0.1",
2529
"core-js": "^2.4.1",
2630
"rxjs": "^6.5.2",
2731
"todomvc-app-css": "^2.1.0",
32+
"todomvc-common": "^1.0.5",
2833
"tslib": "^1.9.0",
2934
"zone.js": "~0.9.1"
3035
},

‎src/app/app-routing.module.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NgModule } from '@angular/core';
2+
import { Routes, RouterModule, PreloadAllModules } from '@angular/router';
3+
4+
const routes: Routes = [
5+
{
6+
path: '',
7+
loadChildren: () => import('./todos/todos.module').then(m => m.TodosModule)
8+
},
9+
];
10+
11+
@NgModule({
12+
imports: [RouterModule.forRoot(routes, {
13+
preloadingStrategy: PreloadAllModules
14+
})],
15+
exports: [RouterModule]
16+
})
17+
export class AppRoutingModule { }

‎src/app/app.component.html

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1 @@
1-
<section class="todoapp">
2-
<header class="header">
3-
<h1>todos</h1>
4-
<app-new-todo></app-new-todo>
5-
</header>
6-
<router-outlet></router-outlet>
7-
<app-footer></app-footer>
8-
</section>
9-
<footer class="info">
10-
<p>Double-click to edit a todo</p>
11-
<p>Written by <a href="http://twitter.com/nicobytes">Nicolas Molina</a></p>
12-
<p>Using <a href="https://angular.io/">Angular</a> and <a href="https://ngrx.github.io/">ngrx/store</a></p>
13-
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
14-
</footer>
1+
<router-outlet></router-outlet>

‎src/app/app.component.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
11
import { Component } from '@angular/core';
2-
import { Store } from '@ngrx/store';
3-
4-
import { AppState } from './../redux/app.reducer';
5-
import { Todo } from './../redux/todo/todo.model';
6-
import * as TodoActions from './../redux/todo/todo.actions';
72

83
@Component({
94
selector: 'app-root',
105
templateUrl: './app.component.html'
116
})
127
export class AppComponent {
138

14-
constructor(
15-
private store: Store<AppState>,
16-
) {
17-
this.populateTodos();
18-
this.updateTodos();
19-
}
20-
21-
private populateTodos() {
22-
const todos: Todo[] = JSON.parse(localStorage.getItem('angular-ngrx-todos') || '[]');
23-
this.store.dispatch(new TodoActions.PopulateTodosAction(todos));
24-
}
25-
26-
private updateTodos() {
27-
this.store.select('todos')
28-
.subscribe(todos => {
29-
localStorage.setItem('angular-ngrx-todos', JSON.stringify(todos));
30-
});
31-
}
9+
constructor() {}
3210

3311
}

‎src/app/app.module.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
11
import { BrowserModule } from '@angular/platform-browser';
2+
import { HttpClientModule } from '@angular/common/http';
3+
import { LocationStrategy, HashLocationStrategy, } from '@angular/common';
24
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
35
import { NgModule } from '@angular/core';
4-
import { RouterModule, Routes } from '@angular/router';
56
import { StoreModule } from '@ngrx/store';
7+
import { EffectsModule } from '@ngrx/effects';
8+
import { StoreRouterConnectingModule } from '@ngrx/router-store';
69
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
7-
import { rootReducer } from './../redux/app.reducer';
810

9-
import {
10-
LocationStrategy,
11-
HashLocationStrategy,
12-
} from '@angular/common';
11+
import { environment } from '@environments/environment';
1312

1413
import { AppComponent } from './app.component';
15-
import { TodoComponent } from './todo/todo.component';
16-
import { TodoListComponent } from './todo-list/todo-list.component';
17-
import { FooterComponent } from './footer/footer.component';
18-
import { NewTodoComponent } from './new-todo/new-todo.component';
19-
20-
const routes: Routes = [
21-
// basic routes
22-
{ path: '', component: TodoListComponent, pathMatch: 'full' },
23-
{ path: ':filter', component: TodoListComponent }
24-
];
14+
import { AppRoutingModule } from './app-routing.module';
15+
import { reducers, metaReducers } from './reducers';
16+
import { CustomSerializer } from './reducers/custom-route-serializer';
2517

2618
@NgModule({
2719
declarations: [
28-
AppComponent,
29-
TodoComponent,
30-
TodoListComponent,
31-
FooterComponent,
32-
NewTodoComponent
20+
AppComponent
3321
],
3422
imports: [
3523
BrowserModule,
3624
FormsModule,
3725
ReactiveFormsModule,
38-
RouterModule.forRoot(routes),
39-
StoreModule.forRoot(rootReducer),
40-
StoreDevtoolsModule.instrument({
41-
maxAge: 25 // Retains last 25 states
42-
})
26+
HttpClientModule,
27+
AppRoutingModule,
28+
StoreRouterConnectingModule.forRoot({
29+
serializer: CustomSerializer
30+
}),
31+
StoreModule.forRoot(reducers, { metaReducers }),
32+
EffectsModule.forRoot([]),
33+
StoreDevtoolsModule.instrument({ maxAge: 25, logOnly: environment.production })
4334
],
4435
providers: [
36+
{ provide: 'API_URL', useValue: environment.api },
4537
{ provide: LocationStrategy, useClass: HashLocationStrategy }
4638
],
4739
bootstrap: [AppComponent]

‎src/app/footer/footer.component.html

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎src/app/footer/footer.component.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

‎src/app/new-todo/new-todo.component.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)