debugMetaStore.tsx 750 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. this.reset();
  18. },
  19. reset() {
  20. this.filter = null;
  21. this.trigger(this.get());
  22. },
  23. updateFilter(word) {
  24. this.filter = word;
  25. this.trigger(this.get());
  26. },
  27. get() {
  28. return {
  29. filter: this.filter,
  30. };
  31. },
  32. };
  33. const DebugMetaStore = createStore(storeConfig);
  34. export {DebugMetaStore};
  35. export default DebugMetaStore;