import throttle from 'lodash.throttle';
import sortedObject from './sortedObject';
import {createStore} from 'redux';
import reducer from './Reducer';


const Store = {
  ...createStore(reducer),


  getDefaultParams() {
    return this.getState().defaultParams;
  },


  getCleanQuery() {
    const cleanQuery = {...this.getState().query};

    Object.keys(this.getDefaultParams()).forEach(key => {
      if (cleanQuery[key] === this.getDefaultParams()[key]) {
        delete cleanQuery[key];
      }
    });
    return sortedObject(cleanQuery);
  },


  getQuery() {
    return this.getState().query;
  },


  getType() {
    return this.getState().type;
  },


  addThrottledChangeListener(callback, timeout = 200, options = {leading: false, trailing: true}) {
    const throttledCallback = throttle(callback, timeout, options);
    const unsubscribe = this.subscribe(throttledCallback);

    return () => {
      unsubscribe();
      throttledCallback.cancel();
    };
  }
};

export default Store;

@@ -966,16 +966,90 @@
 %0A    %7D;%0A
+  %7D,%0A%0A%0A  addChangeListener(...args) %7B%0A    return this.subscribe(...args);%0A
   %7D%0A%7D;%0A%0A

add Store.addChangeListener for backward compatibility