sentryAppInstallationsStore.tsx 1.1 KB

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