debugMetaStore.tsx 883 B

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