externalIssueStore.tsx 1010 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {createStore} from 'reflux';
  2. import type {StrictStoreDefinition} from 'sentry/stores/types';
  3. import type {PlatformExternalIssue} from 'sentry/types/integrations';
  4. interface ExternalIssueStoreDefinition
  5. extends StrictStoreDefinition<PlatformExternalIssue[]> {
  6. add(issue: PlatformExternalIssue): void;
  7. load(items: PlatformExternalIssue[]): void;
  8. }
  9. const storeConfig: ExternalIssueStoreDefinition = {
  10. state: [],
  11. init() {
  12. // XXX: Do not use `this.listenTo` in this store. We avoid usage of reflux
  13. // listeners due to their leaky nature in tests.
  14. this.state = [];
  15. },
  16. getState() {
  17. return this.state;
  18. },
  19. load(items: PlatformExternalIssue[]) {
  20. this.state = items;
  21. this.trigger(items);
  22. },
  23. add(issue: PlatformExternalIssue) {
  24. if (!this.state.some(i => i.id === issue.id)) {
  25. this.state = this.state.concat([issue]);
  26. this.trigger(this.state);
  27. }
  28. },
  29. };
  30. const ExternalIssueStore = createStore(storeConfig);
  31. export default ExternalIssueStore;