12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import {createStore, StoreDefinition} from 'reflux';
- import {Repository} from 'sentry/types';
- type State = {
- orgSlug?: string;
- repositories?: Repository[];
- repositoriesError?: Error;
- repositoriesLoading?: boolean;
- };
- interface RepositoryStoreDefinition extends StoreDefinition {
- get(): State;
- loadRepositories(orgSlug: string): void;
- loadRepositoriesError(error: Error): void;
- loadRepositoriesSuccess(data: Repository[]): void;
- resetRepositories(): void;
- state: State;
- }
- 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(storeConfig);
- export default RepositoryStore;
|