UNPKG

apisearch-events-ui

Version:

Javascript User Interface to visualize all events data.

51 lines (43 loc) 1.35 kB
import ApisearchDispatcher from '../dispatcher' import { EventEmitter } from "events"; /** * Search effectiveness widget store */ class SearchEffectivenessStore extends EventEmitter { constructor(initialQuery) { super(); this.dirty = true; this.currentQuery = initialQuery; this.data = { queriesWithResult: {}, queriesWithoutResult: {} }; this.registerReducer(); } registerReducer() { ApisearchDispatcher.register(action => { const { result, updatedQuery } = action.payload; this.currentQuery = updatedQuery; /** * Queries WITH result action */ if (action.type === 'RENDER_QUERIES_WITH_RESULTS') { this.data = { ...this.data, queriesWithResult: result.aggregations.aggregations }; } /** * Queries WITH NO result action */ if (action.type === 'RENDER_QUERIES_WITH_NO_RESULTS') { this.data = { ...this.data, queriesWithoutResult: result.aggregations.aggregations }; } this.emit('render'); }); } } export default SearchEffectivenessStore;