Skip to content

Commit

Permalink
chore: paste in original counter example from ngrx-store
Browse files Browse the repository at this point in the history
  • Loading branch information
ersimont committed Nov 26, 2017
1 parent 7e43b68 commit cf6ab2e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 39 deletions.
2 changes: 0 additions & 2 deletions demos/counter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"@angular/platform-browser-dynamic": "^5.0.0",
"@ngrx/store": "^4.1.0",
"core-js": "^2.4.1",
"micro-dash": "^1.0.0",
"ng-app-state": "^2.0.0",
"rxjs": "^5.5.2",
"zone.js": "^0.8.18"
},
Expand Down
8 changes: 2 additions & 6 deletions demos/counter/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { StoreModule } from '@ngrx/store';
import { ngAppStateReducer } from 'ng-app-state';
import { CounterStore } from './counter-store';
import { counterReducer } from './counter';
import { MyAppComponent } from './my-app.component';

@NgModule({
Expand All @@ -11,10 +10,7 @@ import { MyAppComponent } from './my-app.component';
],
imports: [
BrowserModule,
StoreModule.forRoot({}, {metaReducers: [ngAppStateReducer]}),
],
providers: [
CounterStore,
StoreModule.forRoot({counter: counterReducer}),
],
bootstrap: [MyAppComponent],
})
Expand Down
3 changes: 0 additions & 3 deletions demos/counter/src/app/counter-state.ts

This file was deleted.

11 changes: 0 additions & 11 deletions demos/counter/src/app/counter-store.ts

This file was deleted.

21 changes: 21 additions & 0 deletions demos/counter/src/app/counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Action } from '@ngrx/store';

export const INCREMENT = 'INCREMENT';
export const DECREMENT = 'DECREMENT';
export const RESET = 'RESET';

export function counterReducer(state: number = 0, action: Action) {
switch (action.type) {
case INCREMENT:
return state + 1;

case DECREMENT:
return state - 1;

case RESET:
return 0;

default:
return state;
}
}
23 changes: 14 additions & 9 deletions demos/counter/src/app/my-app.component.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
import { Component } from '@angular/core';
import { StoreObject } from 'ng-app-state';
import { CounterStore } from './counter-store';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { DECREMENT, INCREMENT, RESET } from './counter';

interface AppState {
counter: number;
}

@Component({
selector: 'my-app',
template: `
<button (click)="increment()">Increment</button>
<div>Current Count: {{ valueStore.$ | async }}</div>
<div>Current Count: {{ counter | async }}</div>
<button (click)="decrement()">Decrement</button>
<button (click)="reset()">Reset Counter</button>
`,
})
export class MyAppComponent {
valueStore: StoreObject<number>;
counter: Observable<number>;

constructor(store: CounterStore) {
this.valueStore = store('value');
constructor(private store: Store<AppState>) {
this.counter = store.select('counter');
}

increment() {
this.valueStore.set(this.valueStore.state() + 1);
this.store.dispatch({type: INCREMENT});
}

decrement() {
this.valueStore.set(this.valueStore.state() - 1);
this.store.dispatch({type: DECREMENT});
}

reset() {
this.valueStore.set(0);
this.store.dispatch({type: RESET});
}
}
8 changes: 0 additions & 8 deletions demos/counter/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2899,10 +2899,6 @@ methods@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"

micro-dash@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/micro-dash/-/micro-dash-1.0.0.tgz#195e80388c5544b14266d09bd13ca19041b713d0"

micromatch@^2.1.5, micromatch@^2.3.11:
version "2.3.11"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
Expand Down Expand Up @@ -3044,10 +3040,6 @@ negotiator@0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"

ng-app-state@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ng-app-state/-/ng-app-state-2.0.0.tgz#edfde5d6e1daebe0ccc5af5c0b21f8e2e1761437"

no-case@^2.2.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.1.tgz#7aeba1c73a52184265554b7dc03baf720df80081"
Expand Down

0 comments on commit cf6ab2e

Please sign in to comment.