Skip to content

Commit

Permalink
feat: add todos, lazy reducer, big input custom component
Browse files Browse the repository at this point in the history
  • Loading branch information
tomastrajan committed May 20, 2017
1 parent 81c25a0 commit 878662e
Show file tree
Hide file tree
Showing 37 changed files with 522 additions and 46 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
"@ngrx/core": "^1.2.0",
"@ngrx/effects": "^2.0.3",
"@ngrx/store": "^2.2.2",
"@types/node-uuid": "0.0.28",
"bootstrap": "^4.0.0-alpha.6",
"classlist.js": "^1.1",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"intl": "^1.2.5",
"node-uuid": "^1.4.8",
"rxjs": "^5.1.0",
"web-animations-js": "^2.2.5",
"zone.js": "^0.8.4"
Expand Down
8 changes: 1 addition & 7 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@

</md-toolbar>

<div class="container">
<div class="row">
<div class="col-sm-12">
<router-outlet></router-outlet>
</div>
</div>
</div>
<router-outlet></router-outlet>

<div class="push"></div>

Expand Down
23 changes: 15 additions & 8 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { StoreModule, combineReducers } from '@ngrx/store';
import { StoreModule, combineReducers, ActionReducer } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';

import { settingsReducer, SettingsEffects } from '../settings';
Expand All @@ -10,18 +10,25 @@ import {
localStorageInitStateMiddleware
} from './local-storage/local-storage.middleware';

const rootReducer = localStorageInitStateMiddleware(
combineReducers({
settings: settingsReducer
})
);

export function reducer(state, action) { return rootReducer(state, action); }
export function createReducer(asyncReducers = {}): ActionReducer<any> {
return localStorageInitStateMiddleware(
combineReducers(Object.assign({
settings: settingsReducer
}, asyncReducers))
);
}

const reducer = createReducer();

export function reducerAoT(state, action) {
return reducer(state, action);
}

@NgModule({
imports: [
CommonModule,
StoreModule.provideStore((reducer)),
StoreModule.provideStore(reducerAoT),
EffectsModule.run(SettingsEffects)
],
declarations: [],
Expand Down
1 change: 1 addition & 0 deletions src/app/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './local-storage/local-storage.service';
export * from './local-storage/local-storage.middleware';
export * from './core.module';
21 changes: 16 additions & 5 deletions src/app/examples/examples-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { ExamplesComponent } from './examples/examples.component';
import { TodosComponent } from './todos/todos.component';
import { StockMarketComponent } from './stock-market/stock-market.component';

const routes: Routes = [
{
path: '',
redirectTo: 'todos',
pathMatch: 'full'
}, {
path: 'todos',
component: TodosComponent
component: ExamplesComponent,
children: [
{
path: '',
redirectTo: 'todos',
pathMatch: 'full'
}, {
path: 'todos',
component: TodosComponent
}, {
path: 'stock-market',
component: StockMarketComponent
}
]
}
];

Expand Down
23 changes: 20 additions & 3 deletions src/app/examples/examples.module.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import { NgModule } from '@angular/core';
import { Store } from '@ngrx/store';

import { CoreModule } from '../core';
import { CoreModule, createReducer } from '../core';
import { SharedModule } from '../shared';

import { ExamplesRoutingModule } from './examples-routing.module';
import { TodosComponent } from './todos/todos.component';
import { ExamplesComponent } from './examples/examples.component';
import { StockMarketComponent } from './stock-market/stock-market.component';
import { StockMarketService } from './stock-market/stock-market.service';

import { todosReducer } from './todos/todos.reducer';

export const appReducerWithExamples = createReducer({
todos: todosReducer
});

@NgModule({
imports: [
CoreModule,
SharedModule,
ExamplesRoutingModule
],
declarations: [TodosComponent]
declarations: [TodosComponent, ExamplesComponent, StockMarketComponent],
providers: [StockMarketService]
})
export class ExamplesModule { }
export class ExamplesModule {

constructor(private store: Store<any> ) {
store.replaceReducer(appReducerWithExamples);
}

}
10 changes: 10 additions & 0 deletions src/app/examples/examples/examples.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<nav md-tab-nav-bar>
<a md-tab-link
*ngFor="let e of examples"
[routerLink]="e.link"
routerLinkActive #rla="routerLinkActive"
[active]="rla.isActive">
{{e.label}}
</a>
</nav>
<router-outlet></router-outlet>
3 changes: 3 additions & 0 deletions src/app/examples/examples/examples.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nav {
margin-bottom: 20px;
}
34 changes: 34 additions & 0 deletions src/app/examples/examples/examples.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';

import { SharedModule } from '../../shared';
import { CoreModule } from '../../core';

import { ExamplesComponent } from './examples.component';

describe('ExamplesComponent', () => {
let component: ExamplesComponent;
let fixture: ComponentFixture<ExamplesComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
SharedModule,
CoreModule
],
declarations: [ ExamplesComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ExamplesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should be created', () => {
expect(component).toBeTruthy();
});
});
20 changes: 20 additions & 0 deletions src/app/examples/examples/examples.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'anms-examples',
templateUrl: './examples.component.html',
styleUrls: ['./examples.component.scss']
})
export class ExamplesComponent implements OnInit {

examples = [
{ link: 'todos', label: 'Todos' },
{ link: 'stock-market', label: 'Stock Market' },
];

constructor() { }

ngOnInit() {
}

}
3 changes: 3 additions & 0 deletions src/app/examples/stock-market/stock-market.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
stock-market works!
</p>
Empty file.
25 changes: 25 additions & 0 deletions src/app/examples/stock-market/stock-market.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { StockMarketComponent } from './stock-market.component';

describe('StockMarketComponent', () => {
let component: StockMarketComponent;
let fixture: ComponentFixture<StockMarketComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ StockMarketComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(StockMarketComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should be created', () => {
expect(component).toBeTruthy();
});
});
15 changes: 15 additions & 0 deletions src/app/examples/stock-market/stock-market.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'anms-stock-market',
templateUrl: './stock-market.component.html',
styleUrls: ['./stock-market.component.scss']
})
export class StockMarketComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
15 changes: 15 additions & 0 deletions src/app/examples/stock-market/stock-market.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { TestBed, inject } from '@angular/core/testing';

import { StockMarketService } from './stock-market.service';

describe('StockMarketService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [StockMarketService]
});
});

it('should be created', inject([StockMarketService], (service: StockMarketService) => {
expect(service).toBeTruthy();
}));
});
8 changes: 8 additions & 0 deletions src/app/examples/stock-market/stock-market.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@angular/core';

@Injectable()
export class StockMarketService {

constructor() { }

}
45 changes: 42 additions & 3 deletions src/app/examples/todos/todos.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
<p>
todos works!
</p>
<div class="container">
<div class="row">
<div class="offset-md-2 col-md-8 entry">
<anms-big-input placeholder="I want to do..."
[value]="newTodo"
(keyup)="onNewTodoChange($event.target.value)"
(keyup.enter)="onAddTodo()">
<anms-big-input-action icon="add" color="accent"
(click)="onAddTodo()"
[disabled]="newTodo.length < 4">
</anms-big-input-action>
<anms-big-input-action icon="delete_forever" disabled></anms-big-input-action>
</anms-big-input>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h2>Todo List</h2>
<md-card *ngFor="let todo of todos.items" class="todo">
{{todo.name}}
</md-card>
<br>
</div>
<div class="offset-md-1 col-md-5">
<h2>Todo Example</h2>
<p>
This is a classic <code>todo</code> example with support for
adding, toggling, removing and filtering of the todo items.
</p>
<p>
State handling is implemented using <code>ngrx</code> module
and support for lazy loaded reducers (this is a lazy loaded feature module).
</p>
<p>
Todos are persisted into local storage so you should see your todos
also on later visits when using the same browser.
</p>
<br>
</div>
</div>

</div>
8 changes: 8 additions & 0 deletions src/app/examples/todos/todos.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.entry {
margin-top: 40px;
margin-bottom: 40px;
}

.todo {
margin-bottom: 10px;
}
10 changes: 9 additions & 1 deletion src/app/examples/todos/todos.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CoreModule } from '../../core';
import { SharedModule } from '../../shared';
import { ExamplesModule } from '../examples.module';

import { TodosComponent } from './todos.component';

describe('TodosComponent', () => {
Expand All @@ -8,7 +12,11 @@ describe('TodosComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TodosComponent ]
imports: [
CoreModule,
SharedModule,
ExamplesModule
]
})
.compileComponents();
}));
Expand Down

0 comments on commit 878662e

Please sign in to comment.