serverSideSamplingStore.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {createStore} from 'reflux';
  2. import {SamplingDistribution, SamplingSdkVersion} from 'sentry/types/sampling';
  3. import {makeSafeRefluxStore} from 'sentry/utils/makeSafeRefluxStore';
  4. import {CommonStoreDefinition} from './types';
  5. type State = {
  6. samplingDistribution: SamplingDistribution;
  7. samplingSdkVersions: SamplingSdkVersion[];
  8. };
  9. interface ServerSideSamplingStoreDefinition extends CommonStoreDefinition<State> {
  10. loadSamplingDistributionSuccess(data: SamplingDistribution): void;
  11. loadSamplingSdkVersionsSuccess(data: SamplingSdkVersion[]): void;
  12. reset(): void;
  13. }
  14. const storeConfig: ServerSideSamplingStoreDefinition = {
  15. state: {
  16. samplingDistribution: {},
  17. samplingSdkVersions: [],
  18. },
  19. reset() {
  20. this.state = {
  21. samplingDistribution: {},
  22. samplingSdkVersions: [],
  23. };
  24. this.trigger(this.state);
  25. },
  26. getState() {
  27. return this.state;
  28. },
  29. loadSamplingSdkVersionsSuccess(data: SamplingSdkVersion[]) {
  30. this.state = {
  31. ...this.state,
  32. samplingSdkVersions: data,
  33. };
  34. this.trigger(this.state);
  35. },
  36. loadSamplingDistributionSuccess(data: SamplingDistribution) {
  37. this.state = {
  38. ...this.state,
  39. samplingDistribution: data,
  40. };
  41. this.trigger(this.state);
  42. },
  43. };
  44. export const ServerSideSamplingStore = createStore(makeSafeRefluxStore(storeConfig));