import * as queryAction from '../actions/query' ; import { Query , parseQueryToQueryString , parseQueryToRouterString } from '../models' ; import { fromRegExp } from '../utils' ; extends Query prop prop prop prop prop prop prop export interface State extends Query { relocateAfter : boolean ; } /**
 * There is always a need of initial state to be passed onto the store.
 */ export const initialState = { displayString : '' , queryString : '' , routerString : '' , filter : { video : false , image : false } , location : null , timeBound : { since : null , until : null } , from : false , relocateAfter : false } ; /**
 * The actual reducer function. Reducers can be thought of as the tables in the DataBase.
 * These are the functions which are responsible for maintaing, and updating the
 * `State` of the application they control.
 *
 * Here the reducer cotrols that part of the state which is shows the state of the application
 * wheather it is searching and what is it searching for.
 */ export function reducer ( state = initialState , action ) { switch ( action . type ) { case queryAction . ActionTypes . VALUE_CHANGE : { const query = action . payload ; const isFromQuery = ( fromRegExp . exec ( query ) ) ? true : false ; return Object . assign ( { } , state , { displayString : query , from : isFromQuery , } ) ; } case queryAction . ActionTypes . FILTER_CHANGE : { const filterList = action . payload ; return Object . assign ( { } , state , { filter : filterList } ) ; } case queryAction . ActionTypes . TIME_BOUND_CHANGE : { const timeBound = action . payload ; return Object . assign ( { } , state , { timeBound } ) ; } case queryAction . ActionTypes . LOCATION_CHANGE : { const location = action . payload ; return Object . assign ( { } , state , { location } ) ; } case queryAction . ActionTypes . QUERY_CHANGE : { const query = action . payload ; if ( query ) { return Object . assign ( { } , query ) ; } else { return Object . assign ( { } , state , { queryString : parseQueryToQueryString ( state ) , routerString : parseQueryToRouterString ( state ) } ) ; } } case queryAction . ActionTypes . RELOCATE_AFTER_QUERY_SET : { return Object . assign ( { } , state , { relocateAfter : true } ) ; } case queryAction . ActionTypes . RELOCATE_AFTER_QUERY_RESET : { return Object . assign ( { } , state , { relocateAfter : false } ) ; } default : { return state ; } } } /**
 * Because the data structure is defined within the reducer it is optimal to
 * locate our selector functions at this level. If store is to be thought of
 * as a database, and reducers the tables, selectors can be considered the
 * queries into said database. Remember to keep your selectors small and
 * focused so they can be combined and composed to fit each particular
 * use-case.
 */ export const getQuery = ( state ) => state ; export const getQueryString = ( state ) => state . queryString ; export const getDisplayString = ( state ) => state . displayString ; export const getFilterList = ( state ) => state . filter ; export const getTimeBoundSet = ( state ) => state . timeBound ; export const getLocation = ( state ) => state . location ; export const getIsFromQuery = ( state ) => state . from ;