sentryAppComponentsStore.tsx 924 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {createStore, StoreDefinition} from 'reflux';
  2. import {SentryAppComponent} from 'sentry/types';
  3. export interface SentryAppComponentsStoreDefinition extends StoreDefinition {
  4. get: (uuid: string) => SentryAppComponent | undefined;
  5. getAll: () => SentryAppComponent[];
  6. getInitialState: () => SentryAppComponent[];
  7. loadComponents: (items: SentryAppComponent[]) => void;
  8. }
  9. const storeConfig: SentryAppComponentsStoreDefinition = {
  10. items: [],
  11. init() {
  12. this.items = [];
  13. },
  14. getInitialState() {
  15. return this.items;
  16. },
  17. loadComponents(items: SentryAppComponent[]) {
  18. this.items = items;
  19. this.trigger(items);
  20. },
  21. get(uuid: string) {
  22. const items: SentryAppComponent[] = this.items;
  23. return items.find(item => item.uuid === uuid);
  24. },
  25. getAll() {
  26. return this.items;
  27. },
  28. };
  29. const SentryAppComponentsStore = createStore(storeConfig);
  30. export default SentryAppComponentsStore;