externalIssueStore.tsx 1.1 KB

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