sdkUpdatesStore.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {createStore} from 'reflux';
  2. import type {ProjectSdkUpdates} from 'sentry/types/project';
  3. import type {StrictStoreDefinition} from './types';
  4. /**
  5. * Org slug mapping to SDK updates
  6. */
  7. type State = Map<string, ProjectSdkUpdates[]>;
  8. interface SdkUpdatesStoreDefinition extends StrictStoreDefinition<State> {
  9. getUpdates(orgSlug: string): ProjectSdkUpdates[] | undefined;
  10. isSdkUpdatesLoaded(orgSlug: string): boolean;
  11. loadSuccess(orgSlug: string, data: ProjectSdkUpdates[]): void;
  12. }
  13. const storeConfig: SdkUpdatesStoreDefinition = {
  14. state: new Map(),
  15. init() {
  16. // XXX: Do not use `this.listenTo` in this store. We avoid usage of reflux
  17. // listeners due to their leaky nature in tests.
  18. },
  19. loadSuccess(orgSlug, data) {
  20. this.state.set(orgSlug, data);
  21. this.trigger(this.state);
  22. },
  23. getUpdates(orgSlug) {
  24. return this.state.get(orgSlug);
  25. },
  26. isSdkUpdatesLoaded(orgSlug) {
  27. return this.state.has(orgSlug);
  28. },
  29. getState() {
  30. return this.state;
  31. },
  32. };
  33. const SdkUpdatesStore = createStore(storeConfig);
  34. export default SdkUpdatesStore;