sdkUpdatesStore.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {createStore} from 'reflux';
  2. import {ProjectSdkUpdates} from 'sentry/types';
  3. import {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. loadSuccess(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. getState() {
  31. return this.orgSdkUpdates;
  32. },
  33. };
  34. const SdkUpdatesStore = createStore(storeConfig);
  35. export default SdkUpdatesStore;