import { Action , createReducer , on } from '@ngrx/store' ; import { ApolloError } from 'apollo-client' ; import { SignInPayload } from '@medium-stories/entities' ; import * as AuthActions from './auth.actions' ; export const AUTH_FEATURE_KEY = 'auth' ; export interface AuthState { /**
     * Login data
     */ signIn : SignInPayload ; /**
     * Sign in errors
     */ signInError ? : ApolloError ; /**
     * Sign in error
     */ signInRun : boolean ; /**
     * Sign out error
     */ signOutError ? : ApolloError ; /**
     * Sign out error
     */ signOutRun : boolean ; } export interface AuthPartialState { readonly [ AUTH_FEATURE_KEY ] : AuthState ; } export const authInitialState = { signIn : null , signInError : null , signInRun : false , signOutError : null , signOutRun : false } ; const authReducer = createReducer ( authInitialState , on ( AuthActions . signInSet , ( state , { payload } ) => ( { ... state , signIn : payload } ) ) , on ( AuthActions . signInClear , state => ( { ... state , signIn : null } ) ) , on ( AuthActions . signInRun , state => ( { ... state , signInError : null , signInRun : true } ) ) , on ( AuthActions . signInSuccess , ( state , { payload } ) => ( { ... state , signIn : null , signInRun : false } ) ) , on ( AuthActions . signInFailure , ( state , { payload } ) => ( { ... state , signInError : payload , signInRun : false } ) ) , on ( AuthActions . signOutRun , state => ( { ... state , signOutError : null , signOutRun : true } ) ) , on ( AuthActions . signOutSuccess , state => ( { ... state , signOutRun : false } ) ) , on ( AuthActions . signOutFailure , ( state , { payload } ) => ( { ... state , signOutError : payload , signOutRun : false } ) ) ) ; export function reducer ( state , action ) { return authReducer ( state , action ) ; }