Skip to content
Snippets Groups Projects
Select Git revision
17 results Searching

UserBuilder.php

Blame
  • manifests.js 1.33 KiB
    import manifesto from 'manifesto.js';
    import ActionTypes from '../actions/action-types';
    
    /**
     * manifestsReducer
     */
    export const manifestsReducer = (state = {}, action) => {
      switch (action.type) {
        case ActionTypes.REQUEST_MANIFEST:
          return {
            ...state,
            [action.manifestId]: {
              ...state[action.manifestId],
              ...action.properties,
              id: action.manifestId,
            },
          };
        case ActionTypes.RECEIVE_MANIFEST:
          return {
            ...state,
            [action.manifestId]: {
              ...state[action.manifestId],
              id: action.manifestId,
              manifestation: manifesto.create(action.manifestJson),
              isFetching: false,
              error: null, // Explicitly set the error to null in case this is a re-fetch
            },
          };
        case ActionTypes.RECEIVE_MANIFEST_FAILURE:
          return {
            ...state,
            [action.manifestId]: {
              ...state[action.manifestId],
              id: action.manifestId,
              error: action.error,
              isFetching: false,
            },
          };
        case ActionTypes.REMOVE_MANIFEST:
          return Object.keys(state).reduce((object, key) => {
            if (key !== action.manifestId) {
              object[key] = state[key]; // eslint-disable-line no-param-reassign
            }
            return object;
          }, {});
        default: return state;
      }
    };