mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 21:13:07 +00:00
use dependency injection for meta reducers
This commit is contained in:
@@ -13,7 +13,6 @@ export function debugMetaReducer(reducer) {
|
|||||||
console.debug('action', action);
|
console.debug('action', action);
|
||||||
console.debug('------------------------------------');
|
console.debug('------------------------------------');
|
||||||
}
|
}
|
||||||
|
|
||||||
return reducer(state, action);
|
return reducer(state, action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,6 +32,6 @@ export function universalMetaReducer(reducer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const appMetaReducers = [
|
export const appMetaReducers = [
|
||||||
// debugMetaReducer,
|
debugMetaReducer,
|
||||||
universalMetaReducer,
|
universalMetaReducer,
|
||||||
];
|
];
|
||||||
|
@@ -4,15 +4,17 @@ import { HttpModule } from '@angular/http';
|
|||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
import { RouterModule } from '@angular/router';
|
import { RouterModule } from '@angular/router';
|
||||||
|
|
||||||
import { StoreModule } from '@ngrx/store';
|
import { StoreModule, MetaReducer, META_REDUCERS } from '@ngrx/store';
|
||||||
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
|
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
|
||||||
import { RouterStateSerializer, StoreRouterConnectingModule } from '@ngrx/router-store';
|
import { RouterStateSerializer, StoreRouterConnectingModule } from '@ngrx/router-store';
|
||||||
|
|
||||||
|
import { storeFreeze } from 'ngrx-store-freeze';
|
||||||
|
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
import { appReducers } from './app.reducer';
|
import { appReducers, AppState } from './app.reducer';
|
||||||
import { appEffects } from './app.effects';
|
import { appEffects } from './app.effects';
|
||||||
|
|
||||||
import { CoreModule } from './core/core.module';
|
import { CoreModule } from './core/core.module';
|
||||||
@@ -27,7 +29,7 @@ import { HeaderComponent } from './header/header.component';
|
|||||||
import { FooterComponent } from './footer/footer.component';
|
import { FooterComponent } from './footer/footer.component';
|
||||||
import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component';
|
import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component';
|
||||||
|
|
||||||
import { GLOBAL_CONFIG, ENV_CONFIG } from '../config';
|
import { GLOBAL_CONFIG, ENV_CONFIG, GlobalConfig } from '../config';
|
||||||
import { EffectsModule } from '@ngrx/effects';
|
import { EffectsModule } from '@ngrx/effects';
|
||||||
import { appMetaReducers } from './app.metareducers';
|
import { appMetaReducers } from './app.metareducers';
|
||||||
|
|
||||||
@@ -37,6 +39,10 @@ export function getConfig() {
|
|||||||
return ENV_CONFIG;
|
return ENV_CONFIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getMetaReducers(config: GlobalConfig): MetaReducer<AppState>[] {
|
||||||
|
return config.production ? appMetaReducers : [...appMetaReducers, storeFreeze];
|
||||||
|
}
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
@@ -47,7 +53,7 @@ export function getConfig() {
|
|||||||
NgbModule.forRoot(),
|
NgbModule.forRoot(),
|
||||||
TranslateModule.forRoot(),
|
TranslateModule.forRoot(),
|
||||||
EffectsModule.forRoot(appEffects),
|
EffectsModule.forRoot(appEffects),
|
||||||
StoreModule.forRoot(appReducers, { metaReducers: appMetaReducers }),
|
StoreModule.forRoot(appReducers),
|
||||||
StoreDevtoolsModule.instrument({ maxAge: 50 }),
|
StoreDevtoolsModule.instrument({ maxAge: 50 }),
|
||||||
StoreRouterConnectingModule,
|
StoreRouterConnectingModule,
|
||||||
TransferHttpModule,
|
TransferHttpModule,
|
||||||
@@ -57,6 +63,11 @@ export function getConfig() {
|
|||||||
provide: GLOBAL_CONFIG,
|
provide: GLOBAL_CONFIG,
|
||||||
useFactory: (getConfig)
|
useFactory: (getConfig)
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: META_REDUCERS,
|
||||||
|
useFactory: getMetaReducers,
|
||||||
|
deps: [GLOBAL_CONFIG]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: RouterStateSerializer,
|
provide: RouterStateSerializer,
|
||||||
useClass: DSpaceRouterStateSerializer
|
useClass: DSpaceRouterStateSerializer
|
||||||
|
Reference in New Issue
Block a user