sdkUpdatesStore.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {createStore} from 'reflux';
  2. import {ProjectSdkUpdates} from 'sentry/types';
  3. import {makeSafeRefluxStore} from 'sentry/utils/makeSafeRefluxStore';
  4. import {CommonStoreDefinition} from './types';
  5. /**
  6. * Org slug mapping to SDK updates
  7. */
  8. type State = Map<string, ProjectSdkUpdates[]>;
  9. type InternalDefinition = {
  10. orgSdkUpdates: State;
  11. };
  12. interface SdkUpdatesStoreDefinition
  13. extends CommonStoreDefinition<State>,
  14. InternalDefinition {
  15. getUpdates(orgSlug: string): ProjectSdkUpdates[] | undefined;
  16. isSdkUpdatesLoaded(orgSlug: string): boolean;
  17. loadSuccess(orgSlug: string, data: ProjectSdkUpdates[]): void;
  18. }
  19. const storeConfig: SdkUpdatesStoreDefinition = {
  20. orgSdkUpdates: new Map(),
  21. unsubscribeListeners: [],
  22. loadSuccess(orgSlug, data) {
  23. this.orgSdkUpdates.set(orgSlug, data);
  24. this.trigger(this.orgSdkUpdates);
  25. },
  26. getUpdates(orgSlug) {
  27. return this.orgSdkUpdates.get(orgSlug);
  28. },
  29. isSdkUpdatesLoaded(orgSlug) {
  30. return this.orgSdkUpdates.has(orgSlug);
  31. },
  32. getState() {
  33. return this.orgSdkUpdates;
  34. },
  35. };
  36. const SdkUpdatesStore = createStore(makeSafeRefluxStore(storeConfig));
  37. export default SdkUpdatesStore;