From b66a70b52679956396d27f17b1ecdc0ce9022e6e Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Thu, 7 Sep 2017 13:06:58 +0200 Subject: [PATCH] fixed rehydrate issue --- src/app/app.metareducers.ts | 13 +++++++------ src/app/browser-app.module.ts | 2 +- src/app/core/data/request-cache.effects.ts | 14 +++----------- .../transfer-state/browser-transfer-state.ts | 1 + 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/app/app.metareducers.ts b/src/app/app.metareducers.ts index 61af007629..fadaa6a991 100644 --- a/src/app/app.metareducers.ts +++ b/src/app/app.metareducers.ts @@ -1,8 +1,7 @@ import { isNotEmpty } from './shared/empty.util'; import { StoreActionTypes } from './store.actions'; -// crude temporary ngrx debugger for use until -// https://github.com/ngrx/platform/issues/97 is fixed +// fallback ngrx debugger let actionCounter = 0; export function debugMetaReducer(reducer) { @@ -26,12 +25,14 @@ export function universalMetaReducer(reducer) { state = Object.assign({}, state, action.payload); break; case StoreActionTypes.REPLAY: - break; default: - - return reducer(state, action); + break; } + return reducer(state, action); } } -export const appMetaReducers = [debugMetaReducer, universalMetaReducer]; +export const appMetaReducers = [ + // debugMetaReducer, + universalMetaReducer, +]; diff --git a/src/app/browser-app.module.ts b/src/app/browser-app.module.ts index 5a896d0e5e..7ba050668c 100644 --- a/src/app/browser-app.module.ts +++ b/src/app/browser-app.module.ts @@ -46,7 +46,6 @@ export function HttpLoaderFactory(http: Http) { }), IdlePreloadModule.forRoot(), // forRoot ensures the providers are only created once RouterModule.forRoot([], { useHash: false, preloadingStrategy: IdlePreload }), - StoreRouterConnectingModule, TranslateModule.forRoot({ loader: { provide: TranslateLoader, @@ -60,6 +59,7 @@ export function HttpLoaderFactory(http: Http) { BrowserTransferStateModule, BrowserTransferStoreModule, EffectsModule.forRoot([BrowserTransferStoreEffects]), + StoreRouterConnectingModule, BrowserAnimationsModule, AppModule ], diff --git a/src/app/core/data/request-cache.effects.ts b/src/app/core/data/request-cache.effects.ts index 8ff41fb9f9..a9c1c24957 100644 --- a/src/app/core/data/request-cache.effects.ts +++ b/src/app/core/data/request-cache.effects.ts @@ -1,8 +1,8 @@ -import { Injectable, Inject } from '@angular/core'; +import { Injectable } from '@angular/core'; import { Actions, Effect } from '@ngrx/effects'; -import { ObjectCacheActionTypes } from '../cache/object-cache.actions'; import { ResetResponseCacheTimestampsAction } from '../cache/response-cache.actions'; +import { StoreActionTypes } from '../../store.actions'; @Injectable() export class RequestCacheEffects { @@ -14,17 +14,9 @@ export class RequestCacheEffects { * * This assumes that the server cached everything a negligible * time ago, and will likely need to be revisited later - * - * This effect should listen for StoreActionTypes.REHYDRATE, - * but can't because you can only have one effect listen to - * an action atm. Github issue: - * https://github.com/ngrx/effects/issues/87 - * - * It's listening for ObjectCacheActionTypes.RESET_TIMESTAMPS - * instead, until there's a solution. */ @Effect() fixTimestampsOnRehydrate = this.actions$ - .ofType(ObjectCacheActionTypes.RESET_TIMESTAMPS) + .ofType(StoreActionTypes.REHYDRATE) .map(() => new ResetResponseCacheTimestampsAction(new Date().getTime())); constructor(private actions$: Actions, ) { } diff --git a/src/modules/transfer-state/browser-transfer-state.ts b/src/modules/transfer-state/browser-transfer-state.ts index d1e0a1ecb0..79d7ee3df0 100644 --- a/src/modules/transfer-state/browser-transfer-state.ts +++ b/src/modules/transfer-state/browser-transfer-state.ts @@ -8,6 +8,7 @@ import { StoreAction, StoreActionTypes } from '../../app/store.actions'; import { AppState } from '../../app/app.reducer'; import { GLOBAL_CONFIG, GlobalConfig } from '../../config'; +import { RouterNavigationAction } from '@ngrx/router-store'; @Injectable() export class BrowserTransferState extends TransferState {