sdkUpdatesStore.tsx 1.0 KB

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