debugMetaStore.tsx 911 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import type {StoreDefinition} from 'reflux';
  2. import {createStore} from 'reflux';
  3. type State = {
  4. filter: string | null;
  5. };
  6. interface DebugMetaStoreInterface extends StoreDefinition {
  7. get(): State;
  8. init(): void;
  9. reset(): void;
  10. updateFilter(word: string): void;
  11. }
  12. type Internals = {
  13. filter: string | null;
  14. };
  15. const storeConfig: StoreDefinition & DebugMetaStoreInterface & Internals = {
  16. filter: null,
  17. init() {
  18. // XXX: Do not use `this.listenTo` in this store. We avoid usage of reflux
  19. // listeners due to their leaky nature in tests.
  20. this.reset();
  21. },
  22. reset() {
  23. this.filter = null;
  24. this.trigger(this.get());
  25. },
  26. updateFilter(word) {
  27. this.filter = word;
  28. this.trigger(this.get());
  29. },
  30. get() {
  31. return {
  32. filter: this.filter,
  33. };
  34. },
  35. };
  36. const DebugMetaStore = createStore(storeConfig);
  37. export {DebugMetaStore};
  38. export default DebugMetaStore;