diff --git a/package.json b/package.json index b2f1e7760b..d3876f5f5a 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,10 @@ "@angularclass/bootloader": "1.0.1", "@angularclass/idle-preload": "1.0.4", "@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.14", + "@ngrx/core": "^1.2.0", + "@ngrx/effects": "^2.0.0", + "@ngrx/store": "^2.2.1", + "@ngrx/store-devtools": "^3.2.2", "angular2-express-engine": "2.1.0-rc.1", "angular2-platform-node": "2.1.0-rc.1", "angular2-universal": "2.1.0-rc.1", diff --git a/src/app/app.actions.ts b/src/app/app.actions.ts new file mode 100644 index 0000000000..3660dc77ac --- /dev/null +++ b/src/app/app.actions.ts @@ -0,0 +1,5 @@ +import { HeaderActions } from "./header/header.actions"; + +export default [ + HeaderActions +]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d69f5e116a..decf650d78 100755 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -7,6 +7,12 @@ import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { HeaderComponent } from './header/header.component'; +import { StoreModule } from "@ngrx/store"; +import { StoreDevtoolsModule } from "@ngrx/store-devtools"; + +import reducers from './app.reducers' +import actions from './app.actions' + @NgModule({ declarations: [ @@ -16,7 +22,29 @@ import { HeaderComponent } from './header/header.component'; imports: [ SharedModule, HomeModule, - AppRoutingModule + AppRoutingModule, + /** + * StoreModule.provideStore is imported once in the root module, accepting a reducer + * function or object map of reducer functions. If passed an object of + * reducers, combineReducers will be run creating your application + * meta-reducer. This returns all providers for an @ngrx/store + * based application. + */ + StoreModule.provideStore(reducers), + /** + * Store devtools instrument the store retaining past versions of state + * and recalculating new states. This enables powerful time-travel + * debugging. + * + * To use the debugger, install the Redux Devtools extension for either + * Chrome or Firefox + * + * See: https://github.com/zalmoxisus/redux-devtools-extension + */ + StoreDevtoolsModule.instrumentOnlyWithExtension(), + ], + providers: [ + actions ] }) export class AppModule { diff --git a/src/app/app.reducers.ts b/src/app/app.reducers.ts new file mode 100644 index 0000000000..415006cd51 --- /dev/null +++ b/src/app/app.reducers.ts @@ -0,0 +1,5 @@ +import { headerReducer } from './header/header.reducer'; + +export default { + headerReducer +} diff --git a/src/app/header/header.actions.ts b/src/app/header/header.actions.ts new file mode 100644 index 0000000000..5fdbe0abc6 --- /dev/null +++ b/src/app/header/header.actions.ts @@ -0,0 +1,26 @@ +import { Injectable } from "@angular/core"; +import { Action } from "@ngrx/store"; + +@Injectable() +export class HeaderActions { + static COLLAPSE = 'dspace/header/COLLAPSE'; + collapse(): Action { + return { + type: HeaderActions.COLLAPSE + } + } + + static EXPAND = 'dspace/header/EXPAND'; + expand(): Action { + return { + type: HeaderActions.EXPAND + } + } + + static TOGGLE = 'dspace/header/TOGGLE'; + toggle(): Action { + return { + type: HeaderActions.TOGGLE + } + } +} diff --git a/src/app/header/header.component.html b/src/app/header/header.component.html index 652b12d920..a4b7cf117c 100644 --- a/src/app/header/header.component.html +++ b/src/app/header/header.component.html @@ -3,11 +3,11 @@ -