debugMetaStore.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {createActions, createStore, StoreDefinition} from 'reflux';
  2. import {makeSafeRefluxStore, SafeStoreDefinition} from 'sentry/utils/makeSafeRefluxStore';
  3. const DebugMetaActions = createActions(['updateFilter']);
  4. type State = {
  5. filter: string | null;
  6. };
  7. interface DebugMetaStoreInterface extends StoreDefinition {
  8. get(): State;
  9. init(): void;
  10. reset(): void;
  11. updateFilter(word: string): void;
  12. }
  13. type Internals = {
  14. filter: string | null;
  15. };
  16. const storeConfig: StoreDefinition &
  17. DebugMetaStoreInterface &
  18. Internals &
  19. SafeStoreDefinition = {
  20. filter: null,
  21. unsubscribeListeners: [],
  22. init() {
  23. this.reset();
  24. this.unsubscribeListeners.push(
  25. this.listenTo(DebugMetaActions.updateFilter, this.updateFilter)
  26. );
  27. },
  28. reset() {
  29. this.filter = null;
  30. this.trigger(this.get());
  31. },
  32. updateFilter(word) {
  33. this.filter = word;
  34. this.trigger(this.get());
  35. },
  36. get() {
  37. return {
  38. filter: this.filter,
  39. };
  40. },
  41. };
  42. const DebugMetaStore = createStore(makeSafeRefluxStore(storeConfig));
  43. export {DebugMetaActions, DebugMetaStore};
  44. export default DebugMetaStore;