externalIssueStore.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {createStore, StoreDefinition} from 'reflux';
  2. import {PlatformExternalIssue} from 'sentry/types';
  3. import {makeSafeRefluxStore} from 'sentry/utils/makeSafeRefluxStore';
  4. interface ExternalIssueStoreDefinition extends StoreDefinition {
  5. add(issue: PlatformExternalIssue): void;
  6. getInitialState(): PlatformExternalIssue[];
  7. load(items: PlatformExternalIssue[]): void;
  8. }
  9. const storeConfig: ExternalIssueStoreDefinition = {
  10. init() {
  11. this.items = [];
  12. },
  13. getInitialState(): PlatformExternalIssue[] {
  14. return this.items;
  15. },
  16. load(items: PlatformExternalIssue[]) {
  17. this.items = items;
  18. this.trigger(items);
  19. },
  20. get(id: string) {
  21. return this.items.find((item: PlatformExternalIssue) => item.id === id);
  22. },
  23. getAll() {
  24. return this.items;
  25. },
  26. add(issue: PlatformExternalIssue) {
  27. if (!this.items.some(i => i.id === issue.id)) {
  28. this.items = this.items.concat([issue]);
  29. this.trigger(this.items);
  30. }
  31. },
  32. };
  33. const ExternalIssueStore = createStore(makeSafeRefluxStore(storeConfig));
  34. export default ExternalIssueStore;