sdkUpdatesStore.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {createStore, StoreDefinition} from 'reflux';
  2. import SdkUpdatesActions from 'sentry/actions/sdkUpdatesActions';
  3. import {ProjectSdkUpdates} from 'sentry/types';
  4. import {makeSafeRefluxStore} from 'sentry/utils/makeSafeRefluxStore';
  5. type InternalDefinition = {
  6. /**
  7. * Org slug mapping to SDK updates
  8. */
  9. orgSdkUpdates: Map<string, ProjectSdkUpdates[]>;
  10. };
  11. interface SdkUpdatesStoreDefinition extends StoreDefinition, InternalDefinition {
  12. getUpdates(orgSlug: string): ProjectSdkUpdates[] | undefined;
  13. isSdkUpdatesLoaded(orgSlug: string): boolean;
  14. onLoadSuccess(orgSlug: string, data: ProjectSdkUpdates[]): void;
  15. }
  16. const storeConfig: SdkUpdatesStoreDefinition = {
  17. orgSdkUpdates: new Map(),
  18. unsubscribeListeners: [],
  19. init() {
  20. this.unsubscribeListeners.push(
  21. this.listenTo(SdkUpdatesActions.load, this.onLoadSuccess)
  22. );
  23. },
  24. onLoadSuccess(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. };
  35. const SdkUpdatesStore = createStore(makeSafeRefluxStore(storeConfig));
  36. export default SdkUpdatesStore;