sdkUpdatesStore.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import Reflux from 'reflux';
  2. import SdkUpdatesActions from 'sentry/actions/sdkUpdatesActions';
  3. import {ProjectSdkUpdates} from 'sentry/types';
  4. type SdkUpdatesStoreInterface = {
  5. getUpdates(orgSlug: string): ProjectSdkUpdates[] | undefined;
  6. isSdkUpdatesLoaded(orgSlug: string): boolean;
  7. onLoadSuccess(orgSlug: string, data: ProjectSdkUpdates[]): void;
  8. };
  9. type Internals = {
  10. /**
  11. * Org slug mapping to SDK updates
  12. */
  13. orgSdkUpdates: Map<string, ProjectSdkUpdates[]>;
  14. };
  15. const storeConfig: Reflux.StoreDefinition & Internals & SdkUpdatesStoreInterface = {
  16. orgSdkUpdates: new Map(),
  17. init() {
  18. this.listenTo(SdkUpdatesActions.load, this.onLoadSuccess);
  19. },
  20. onLoadSuccess(orgSlug, data) {
  21. this.orgSdkUpdates.set(orgSlug, data);
  22. this.trigger(this.orgSdkUpdates);
  23. },
  24. getUpdates(orgSlug) {
  25. return this.orgSdkUpdates.get(orgSlug);
  26. },
  27. isSdkUpdatesLoaded(orgSlug) {
  28. return this.orgSdkUpdates.has(orgSlug);
  29. },
  30. };
  31. const SdkUpdatesStore = Reflux.createStore(storeConfig) as Reflux.Store &
  32. SdkUpdatesStoreInterface;
  33. export default SdkUpdatesStore;