Home > widget-integration > FilterStore

FilterStore class

Store for managing filter state, URL parameter mappings, and filter cache.

This store manages filter-related state including URL parameter shortening, request caching, and state change notifications. It can be extended by Technical Support teams to customize filter behavior for specific shops.

Signature:

export declare class FilterStore 

Remarks

The store implements an LRU (Least Recently Used) cache with a default size of 50 entries to optimize filter performance while managing memory usage. State changes trigger notifications to all registered watchers.

Example

Extend to customize cache size per shop:

window.boostWidgetIntegration.extend('FilterStore', (FilterStore) => {
  return class CustomFilterStore extends FilterStore {
    setCacheEntry(key, value) {
      const timestamp = new Date().getTime();
      this.cache.value.set(key, { ...value, timestamp });
      // Use larger cache for premium shops
      const maxCacheSize = this.isPremiumShop() ? 100 : 50;
      // Implement custom eviction logic
    }
  };
});

Constructors

Constructor

Modifiers

Description

(constructor)()

Constructs a new instance of the FilterStore class

Properties

Property

Modifiers

Type

Description

events

Signal<Map<EventName, Callback[]>>

Map of event names to their registered callback functions.

state

Signal<FilterStates>

Reactive signal containing the current filter state.

Methods

Method

Modifiers

Description

clearCache()

Clears all cached filter results.

Removes all entries from the cache. Use this when filter configuration changes or when you need to force fresh data fetching for all subsequent requests.

getCacheEntry(key)

Retrieves a cached filter result by its key.

getState()

Retrieves the entire current filter state.

getState(key)

Retrieves a specific property from the current filter state.

hasCacheEntry(key)

Checks whether a specific cache entry exists.

initShortenMaps(shortenUrlParamList)

Initializes URL parameter shortening maps from the provided configuration.

Creates bidirectional mappings between long and short parameter names for URL optimization. This reduces URL length while maintaining readability in the application code.

notifyWatchers()

protected

Notifies all registered watchers of state changes.

This method is called automatically after setState(). Override this method to customize notification behavior, such as debouncing notifications or filtering which watchers to notify based on shop-specific logic.

setCacheEntry(key, value)

Stores a filter result in the cache with automatic LRU eviction.

Adds or updates a cache entry with the current timestamp. When the cache reaches its maximum size (50 entries), the oldest entry is automatically removed using LRU (Least Recently Used) eviction strategy.

setState(newState)

Updates the filter state with new values and notifies all watchers.

This method merges the provided partial state with the current state and triggers notifications to all registered watchers. Override this method to add custom validation or transformation logic before state updates.

watch(callback)

Subscribes to filter state changes.

Watch the entire state for any changes. Use this when you need to react to any state update regardless of which property changed.

watch(key, callback)

Subscribes to changes of a specific filter state property.

Watch a single property for changes. More efficient than watching the entire state when you only care about specific properties.