externalIssueStore.tsx 927 B

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