sdkUpdatesStore.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {createStore} from 'reflux';
  2. import type {ProjectSdkUpdates} from 'sentry/types/project';
  3. import type {CommonStoreDefinition} from './types';
  4. /**
  5. * Org slug mapping to SDK updates
  6. */
  7. type State = Map<string, ProjectSdkUpdates[]>;
  8. type InternalDefinition = {
  9. orgSdkUpdates: State;
  10. };
  11. interface SdkUpdatesStoreDefinition
  12. extends CommonStoreDefinition<State>,
  13. InternalDefinition {
  14. getUpdates(orgSlug: string): ProjectSdkUpdates[] | undefined;
  15. isSdkUpdatesLoaded(orgSlug: string): boolean;
  16. loadSuccess(orgSlug: string, data: ProjectSdkUpdates[]): void;
  17. }
  18. const storeConfig: SdkUpdatesStoreDefinition = {
  19. orgSdkUpdates: new Map(),
  20. init() {
  21. // XXX: Do not use `this.listenTo` in this store. We avoid usage of reflux
  22. // listeners due to their leaky nature in tests.
  23. },
  24. loadSuccess(orgSlug, data) {
  25. this.orgSdkUpdates.set(orgSlug, data);
  26. this.trigger(this.orgSdkUpdates);
  27. },
  28. getUpdates(orgSlug) {
  29. return this.orgSdkUpdates.get(orgSlug);
  30. },
  31. isSdkUpdatesLoaded(orgSlug) {
  32. return this.orgSdkUpdates.has(orgSlug);
  33. },
  34. getState() {
  35. return this.orgSdkUpdates;
  36. },
  37. };
  38. const SdkUpdatesStore = createStore(storeConfig);
  39. export default SdkUpdatesStore;