All files / src/containers/ApiCalls ApiCall.js

100% Statements 18/18
100% Branches 2/2
100% Functions 15/15
100% Lines 16/16
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67              10x 2x 2x     8x       6x       4x       2x             8x       16x       9x       19x       19x       78x       1x       1x       1x      
import _ApiKey from './ApiKey';
import _ApiAction from './ApiAction';
import _ApiState from './ApiState';
import is from 'is_js';
 
export default class ApiCall {
  static find(state, key) {
    if (is.object(key)) {
      const builtKey = ApiCall.Key.create(key);
      return ApiCall.find(state, builtKey);
    }
 
    return state.get('apiCalls').get(key);
  }
 
  static shouldPerform(state, key) {
    return ApiCall.State.shouldPerform(ApiCall.find(state, key));
  }
 
  static createAction(action) {
    return ApiCall.Action.create(action);
  }
 
  static clean(key) {
    return Object.freeze({
      type: ApiCall.API_CALL_CLEAN,
      key,
    });
  }
 
  static getErrors(state) {
    return ApiCall.getAllErrors(state).filter((call) => ! call.disableDefault);
  }
 
  static getAllErrors(state) {
    return state.get('apiCalls').filter((call) => ApiCall.State.hasFailed(call));
  }
 
  static get API_CALL_CLEAN() {
    return 'API_CALL_CLEAN';
  }
 
  static get Action() {
    return _ApiAction;
  }
 
  static get Key() {
    return _ApiKey;
  }
 
  static get State() {
    return _ApiState;
  }
 
  static set Action(param) {
    throw new Error('Not allowed to reassign!');
  }
 
  static set Key(param) {
    throw new Error('Not allowed to reassign!');
  }
 
  static set State(param) {
    throw new Error('Not allowed to reassign!');
  }
}