serverSideSamplingStore.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. fetching: boolean;
  7. samplingDistribution: SamplingDistribution;
  8. samplingSdkVersions: SamplingSdkVersion[];
  9. };
  10. interface ServerSideSamplingStoreDefinition extends CommonStoreDefinition<State> {
  11. loadSamplingDistributionSuccess(data: SamplingDistribution): void;
  12. loadSamplingSdkVersionsSuccess(data: SamplingSdkVersion[]): void;
  13. reset(): void;
  14. setFetching(fetching: boolean): void;
  15. }
  16. const storeConfig: ServerSideSamplingStoreDefinition = {
  17. state: {
  18. samplingDistribution: {},
  19. samplingSdkVersions: [],
  20. fetching: false,
  21. },
  22. reset() {
  23. this.state = {
  24. samplingDistribution: {},
  25. samplingSdkVersions: [],
  26. };
  27. this.trigger(this.state);
  28. },
  29. getState() {
  30. return this.state;
  31. },
  32. setFetching(fetching: boolean) {
  33. this.state.fetching = fetching;
  34. this.trigger(this.state);
  35. },
  36. loadSamplingSdkVersionsSuccess(data: SamplingSdkVersion[]) {
  37. this.state = {
  38. ...this.state,
  39. samplingSdkVersions: data,
  40. };
  41. this.trigger(this.state);
  42. },
  43. loadSamplingDistributionSuccess(data: SamplingDistribution) {
  44. this.state = {
  45. ...this.state,
  46. samplingDistribution: data,
  47. };
  48. this.trigger(this.state);
  49. },
  50. };
  51. export const ServerSideSamplingStore = createStore(makeSafeRefluxStore(storeConfig));