externalIssueStore.tsx 1018 B

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