import { createStoreEmitters } from '../../../store' ; import { UrlParams } from '../../../types/url-params' ; import { urlXStoreModule } from './module' ; import { UrlParamKey } from './types' ; /**
 * The params from  UrlParams that provokes a replace instead of a push in the browser URL
 * state.
 *
 *  internal export const replaceableParams = [ 'scroll' , 'page' ] ; /**
 * Compares new and old  UrlParams to know if not replaceable params have changed.
 *
 *  param newParams - The new  UrlParams to compare.
 *  param oldParams - The old  UrlParams to compare.
 *
 *  returns function shouldPushUrl ( newParams = { } , oldParams = { } ) { const keys = Object . keys ( { ... oldParams , ... newParams } ) ; return keys . some ( key => ! replaceableParams . includes ( key ) && oldParams [ key ] !== newParams [ key ] ) ; } /**
 * Compares new and old  UrlParams to know if replaceable params have changed.
 *
 *  param newParams - The new  UrlParams to compare.
 *  param oldParams - The old  UrlParams to compare.
 *
 *  returns function shouldReplaceUrl ( newParams = { } , oldParams = { } ) { const keys = Object . keys ( { ... oldParams , ... newParams } ) ; return ( keys . some ( key => replaceableParams . includes ( key ) && oldParams [ key ] !== newParams [ key ] ) && ! shouldPushUrl ( newParams , oldParams ) ) ; } /**
 *  StoreEmitters For the URL module.
 *
 *  internal export const urlEmitters = createStoreEmitters ( urlXStoreModule , { PushableUrlStateChanged : { selector : ( _ , getters ) => getters . urlParams , filter : shouldPushUrl } , ReplaceableUrlStateChanged : { selector : ( _ , getters ) => getters . urlParams , filter : shouldReplaceUrl } } ) ;