sentryAppComponentsStore.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import type {StoreDefinition} from 'reflux';
  2. import {createStore} from 'reflux';
  3. import type {SentryAppComponent} from 'sentry/types';
  4. export interface SentryAppComponentsStoreDefinition extends StoreDefinition {
  5. get: (uuid: string) => SentryAppComponent | undefined;
  6. getAll: () => SentryAppComponent[];
  7. getInitialState: () => SentryAppComponent[];
  8. init: () => void;
  9. loadComponents: (items: SentryAppComponent[]) => void;
  10. }
  11. const storeConfig: SentryAppComponentsStoreDefinition = {
  12. items: [],
  13. init() {
  14. // XXX: Do not use `this.listenTo` in this store. We avoid usage of reflux
  15. // listeners due to their leaky nature in tests.
  16. this.items = [];
  17. },
  18. getInitialState() {
  19. return this.items;
  20. },
  21. loadComponents(items: SentryAppComponent[]) {
  22. this.items = items;
  23. this.trigger(items);
  24. },
  25. get(uuid: string) {
  26. const items: SentryAppComponent[] = this.items;
  27. return items.find(item => item.uuid === uuid);
  28. },
  29. getAll() {
  30. return this.items;
  31. },
  32. };
  33. const SentryAppComponentsStore = createStore(storeConfig);
  34. export default SentryAppComponentsStore;