externalIssueStore.tsx 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. 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 = createStore(storeConfig);
  33. export default ExternalIssueStore;