Skip to content

Instantly share code, notes, and snippets.

@falexandre
Last active November 13, 2017 23:35
Show Gist options
  • Save falexandre/52999ab1e468b3609b31da233d546947 to your computer and use it in GitHub Desktop.
Save falexandre/52999ab1e468b3609b31da233d546947 to your computer and use it in GitHub Desktop.
Store Angular
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 { }
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;
}
}
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