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 |
|---|---|---|
|
Constructs a new instance of the |
Properties
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
Map of event names to their registered callback functions. | |||
|
Signal<FilterStates> |
Reactive signal containing the current filter state. |
Methods
|
Method |
Modifiers |
Description |
|---|---|---|
|
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. | ||
|
Retrieves a cached filter result by its key. | ||
|
Retrieves the entire current filter state. | ||
|
Retrieves a specific property from the current filter state. | ||
|
Checks whether a specific cache entry exists. | ||
|
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. | ||
|
|
Notifies all registered watchers of state changes. This method is called automatically after | |
|
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. | ||
|
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. | ||
|
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. | ||
|
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. |