sentryAppComponentsStore.tsx 1.0 KB

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