import { Action , ActionReducer , createReducer , on } from '@ngrx/store' ; import { authIn , authOut , signOutSuccess } from './actions' ; export interface State { uid : string ; isAnonymous : boolean ; ready : boolean ; } export const initialState = { uid : null , isAnonymous : false , ready : false , } ; export const factory = createReducer < State > ( initialState , on ( authIn , ( state , { authData } ) => ( { ... state , ... authData , ready : true , } ) ) , on ( authOut , state => ( { ... state , ... initialState , ready : true , } ) ) ) ; export function reducer ( state , action ) { return factory ( state , action ) ; } /** Clears storage on SignOut */ export function signOutMetaReducer ( _reducer ) { return function ( state , action ) { return _reducer ( action . type === signOutSuccess . type ? undefined : state , action ) ; } ; }