sentryAppComponentsStore.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. init: () => void;
  8. loadComponents: (items: SentryAppComponent[]) => void;
  9. }
  10. const storeConfig: SentryAppComponentsStoreDefinition = {
  11. items: [],
  12. init() {
  13. // XXX: Do not use `this.listenTo` in this store. We avoid usage of reflux
  14. // listeners due to their leaky nature in tests.
  15. this.items = [];
  16. },
  17. getInitialState() {
  18. return this.items;
  19. },
  20. loadComponents(items: SentryAppComponent[]) {
  21. this.items = items;
  22. this.trigger(items);
  23. },
  24. get(uuid: string) {
  25. const items: SentryAppComponent[] = this.items;
  26. return items.find(item => item.uuid === uuid);
  27. },
  28. getAll() {
  29. return this.items;
  30. },
  31. };
  32. const SentryAppComponentsStore = createStore(storeConfig);
  33. export default SentryAppComponentsStore;