Last active
November 13, 2017 23:35
-
-
Save falexandre/52999ab1e468b3609b31da233d546947 to your computer and use it in GitHub Desktop.
Store Angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BrowserModule } from '@angular/platform-browser'; | |
import { NgModule } from '@angular/core'; | |
import { StoreModule } from '@ngrx/store'; | |
import { counterReducer } from './store/counter'; | |
import { AppComponent } from './app.component'; | |
@NgModule({ | |
declarations: [ | |
AppComponent | |
], | |
imports: [ | |
BrowserModule, | |
StoreModule.forRoot({ counter: counterReducer }) | |
], | |
providers: [], | |
bootstrap: [AppComponent] | |
}) | |
export class AppModule { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/ngrx/store | |
https://github.com/angular-redux/form | |
https://github.com/angular-redux/form/tree/master/source/connect | |
https://gist.github.com/falexandre/8b74b4ad186622f6ac0e3be3c23044f4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment