All files / src/data mutations.ts

100% Statements 17/17
50% Branches 1/2
100% Functions 8/8
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 4610x   252x   10x 1x   10x 12x   10x 68x             10x 7x 7x   10x 61x 61x   10x 12x   10x                                
export class MutationStore {
  private store: { [mutationId: string]: MutationStoreValue } = {};
 
  public getStore(): { [mutationId: string]: MutationStoreValue } {
    return this.store;
  }
 
  public get(mutationId: string): MutationStoreValue {
    return this.store[mutationId];
  }
 
  public initMutation(
    mutationId: string,
    mutationString: string,
    variables: Object | undefined,
  ) {
    this.store[mutationId] = {
      mutationString: mutationString,
      variables: variables || {},
      loading: true,
      error: null,
    };
  }
 
  public markMutationError(mutationId: string, error: Error) {
    this.store[mutationId].loading = false;
    this.store[mutationId].error = error;
  }
 
  public markMutationResult(mutationId: string) {
    this.store[mutationId].loading = false;
    this.store[mutationId].error = null;
  }
 
  public reset() {
    this.store = {};
  }
}
 
export interface MutationStoreValue {
  mutationString: string;
  variables: Object;
  loading: boolean;
  error: Error | null;
}