import Cookie from '../cookie'; import Types from '../types'; export class Store{ /** * Store, persistence manager * @param {Object} tf TableFilter instance * * TODO: use localStorage and fallback to cookie persistence */ constructor(tf){ let f = tf.config(); this.duration = !isNaN(f.set_cookie_duration) ? parseInt(f.set_cookie_duration, 10) : 100000; this.tf = tf; this.emitter = tf.emitter; } init(){ this.emitter.on(['after-filtering'], ()=> this.saveFilterValues(this.tf.fltsValuesCookie)); this.emitter.on(['after-clearing-filters'], ()=> this.clearCookies()); } /** * Store filters' values in cookie * @param {String} cookie name */ saveFilterValues(name){ let tf = this.tf; let fltValues = []; if(!tf.rememberGridValues){ return; } //store filters' values for(let i=0; i this.saveFilterValues(this.tf.fltsValuesCookie)); this.emitter.off(['after-clearing-filters'], ()=> this.clearCookies()); } }