Example #1
0
  /**
   * Get all categories
   */
  public all() {
    if(this.state.categories.list.isFetching) {
      return;
    }
    //
    this.onNext({ type: CATEGORY_ACTIONS.FETCH_LIST_REQUEST });
    //
    let onSuccess = ({entities, result}) => {
      this.saveEntity(entities);
      this.onNext({
        type: CATEGORY_ACTIONS.FETCH_LIST_SUCCESS,
        payload: {result}
      });
    }

    let onError = (error) => {
      this.handleApiError(error);
      this.onNext({
        type: CATEGORY_ACTIONS.FETCH_LIST_FAILURE,
        payload: {error}
      })
    }

    this.categoryApi.all().subscribe(onSuccess, onError);
  }
Example #2
0
 /**
  * Find category by id
  * @param {string} instanceName   Instance name e.g. detailsPage
  * @param {string} id              Category id
  */
 public findById(instanceName, id) {
   if(this.state.categories[instanceName].isFetching) {
     return;
   }
   //
   this.onNext({
     type: CATEGORY_ACTIONS.FETCH_REQUEST,
     payload: {id, instanceName}
   });
   //
   let onSuccess = ({ result, entities }) => {
     this.saveEntity(entities);
     this.onNext({
       type: CATEGORY_ACTIONS.FETCH_SUCCESS,
       payload: {result, instanceName}
     });
   }
   //
   let onError = (error) => {
     this.handleApiError(error);
     this.onNext({
       type: CATEGORY_ACTIONS.FETCH_FAILURE,
       payload: {error, instanceName}
     })
   }
   //
   this.categoryApi.findById(id).subscribe(onSuccess, onError);
 }