1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import {createStore, StoreDefinition} from 'reflux';
- import {Repository} from 'sentry/types';
- import {makeSafeRefluxStore} from 'sentry/utils/makeSafeRefluxStore';
- interface RepositoryStoreDefinition extends StoreDefinition {
- get(): {
- orgSlug?: string;
- repositories?: Repository[];
- repositoriesError?: Error;
- repositoriesLoading?: boolean;
- };
- loadRepositories(orgSlug: string): void;
- loadRepositoriesError(error: Error): void;
- loadRepositoriesSuccess(data: Repository[]): void;
- resetRepositories(): void;
- state: {
- orgSlug?: string;
- repositories?: Repository[];
- repositoriesError?: Error;
- repositoriesLoading?: boolean;
- };
- }
- const storeConfig: RepositoryStoreDefinition = {
- state: {
- orgSlug: undefined,
- repositories: undefined,
- repositoriesLoading: undefined,
- repositoriesError: undefined,
- },
- init() {
- this.resetRepositories();
- },
- resetRepositories() {
- this.state = {
- orgSlug: undefined,
- repositories: undefined,
- repositoriesLoading: undefined,
- repositoriesError: undefined,
- };
- this.trigger(this.state);
- },
- loadRepositories(orgSlug: string) {
- this.state = {
- orgSlug,
- repositories: orgSlug === this.state.orgSlug ? this.state.repositories : undefined,
- repositoriesLoading: true,
- repositoriesError: undefined,
- };
- this.trigger(this.state);
- },
- loadRepositoriesError(err: Error) {
- this.state = {
- ...this.state,
- repositories: undefined,
- repositoriesLoading: false,
- repositoriesError: err,
- };
- this.trigger(this.state);
- },
- loadRepositoriesSuccess(data: Repository[]) {
- this.state = {
- ...this.state,
- repositories: data,
- repositoriesLoading: false,
- repositoriesError: undefined,
- };
- this.trigger(this.state);
- },
- get() {
- return {...this.state};
- },
- };
- const RepositoryStore = createStore(makeSafeRefluxStore(storeConfig));
- export default RepositoryStore;
|