How to use the normalizr.normalize function in normalizr

To help you get started, we’ve selected a few normalizr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github redradix / redux-base-app / src / services / users / actions.js View on Github external
export function storeUsers({ data }) {
  const { users, pagination: { total } } = data
  const { entities, result } = normalize(users, [userSchema])
  return batch('STORE_USERS',
    merge(entities),
    setCurrentPage(DOMAIN, result),
    setTotal(DOMAIN, total)
  )
}
github iZaL / my-appointment / src / actions / Auth / login.js View on Github external
return (dispatch,getState) => {
    const currentUser = Object.assign({},getState().entities.users[getState().userReducer.authUserID],{favorites:[]});
    const normalized = normalize(currentUser,Schemas.USER);
    dispatch({type:LOGOUT_USER,entities:normalized.entities});
    const normalizedAppointments = normalize({},Schemas.APPOINTMENT_ARRAY);
    dispatch({type:LOGOUT_USER,entities:normalizedAppointments.entities});

  }
}
github strues / boldr / src / shared / state / modules / media / actions.js View on Github external
.then(res => {
      const medias = res.data;
      const normalizedMedia = normalize(medias, arrayOfMedia);
      dispatch({
        type: t.FETCH_MEDIAS_SUCCESS,
        payload: normalizedMedia,
      });
    })
    .catch(err => {
github iZaL / insta-snap / src / actions / Auth / login.js View on Github external
function loginSuccess(payload) {
  const normalized = normalize({users:payload.data},[userSchema]);
  return {
    type: LOGIN_SUCCESS,
    userID:payload.data.id,
    entities:normalized.entities
  };
}
github phmatray / openjam / src / actions / data / artists.js View on Github external
response => {
      dispatch({
        type: 'FETCH_ARTISTS_SUCCESS',
        filter,
        response: normalize(response, schema.artistList),
      });
    },
    error => {
github pluto-net / scinapse-web-client / app / actions / paperShow.tsx View on Github external
try {
      if (isOpenDropdown) {
        dispatch(ActionCreators.startToGetCollectionsInPaperShowDropdown());
      } else {
        dispatch(ActionCreators.startToGetCollectionsInPaperShow());
      }

      const res = await axios.get(`/members/me/collections`, {
        params: {
          paper_id: String(paperId),
        },
        cancelToken,
      });
      const data = res.data.data;
      const collections = res.data.data.content.map(getSafeCollection);
      const normalizedCollections = normalize(collections, [collectionSchema]);
      const myCollections = { ...data, ...normalizedCollections };

      dispatch(ActionCreators.addEntity(myCollections));
      dispatch(ActionCreators.succeededToGetCollectionsInPaperShow(myCollections));
    } catch (err) {
      if (!Axios.isCancel(err)) {
        dispatch(ActionCreators.failedToGetCollectionsInPaperShow());
        const error = PlutoAxios.getGlobalError(err);
        if (error) {
          alertToast({
            type: 'error',
            message: error.message,
          });
        }
      }
    }
github pluto-net / scinapse-web-client / app / actions / paperShow.tsx View on Github external
return async (dispatch, _getState, { axios }) => {
    try {
      dispatch(ActionCreators.startToGetPaper());
      const res = await axios.get(`/papers/${params.paperId}`, {
        cancelToken: params.cancelToken,
      });
      const paper: Paper = getIdSafePaper(res.data);
      const paperResponse = normalize(paper, paperSchema);

      dispatch(ActionCreators.addEntity(paperResponse));
      dispatch(ActionCreators.getPaper({ paperId: paperResponse.result }));
    } catch (err) {
      if (!Axios.isCancel(err)) {
        const error = PlutoAxios.getGlobalError(err);
        dispatch(ActionCreators.failedToGetPaper({ statusCode: (error as CommonError).status }));
        throw err;
      }
    }
  };
}
github freeCodeCamp / pantry-for-good / client / store / middleware / api.js View on Github external
response.json().then(json => {
        if (!response.ok) return Promise.reject({ ...json, status: response.status })
        if (responseSchema) return normalize(json, responseSchema)
        if (schema) return normalize(json, schema)
        return json
      })
    )
github DalerAsrorov / componofy / src / reducers / finalPlaylists.js View on Github external
receivedAt = action.receivedAt;
      playlist = clone(action.playlist);
      playlists = clone(state.playlists);
      let trackToAdd = clone(action.track);

      playlist.isOpen = false;

      if (playlists.entities && playlists.entities.playlists[playlist.id]) {
        playlist = playlists.entities.playlists[playlist.id];
        playlist.tracks.list.push(trackToAdd.id);
        playlists.entities.tracks[trackToAdd.id] = trackToAdd;
      } else {
        playlist.tracks.list = playlist.tracks.list.filter(
          track => track.id === trackToAdd.id
        );
        normalizedPlaylist = normalize(playlist, playlistSchema);
        playlists = mergeDeepLeft(state.playlists, normalizedPlaylist);
      }

      return Object.assign({}, state, {
        lastUpdated: receivedAt,
        playlists
      });
    case REMOVE_PLAYLIST_FROM_FINAL:
      receivedAt = action.receivedAt;
      let statePlaylists = clone(state.playlists);
      playlists = statePlaylists.entities.playlists;

      delete playlists[action.playlist.id];

      return Object.assign({}, state, {
        playlists: statePlaylists,
github slaylines / bundlers-comparison / app / src / actions / user / index.js View on Github external
.then(data => {
      const typeMap = flow(
        filter(isTrack),
        map(toIdAndType)
      )(data.collection);

      dispatch(mergeTrackTypesTrack(filter((value) => value.type === trackTypes.TRACK, typeMap)));
      dispatch(mergeTrackTypesRepost(filter((value) => value.type === trackTypes.TRACK_REPOST, typeMap)));

      const activitiesMap = flow(
        filter(isTrack),
        map('origin')
      )(data.collection);

      const normalized = normalize(activitiesMap, arrayOf(trackSchema));
      dispatch(mergeEntities(normalized.entities));
      dispatch(mergeActivities(normalized.result));

      dispatch(setPaginateLink(data.next_href, paginateLinkTypes.ACTIVITIES));
      dispatch(setRequestInProcess(false, requestType));
    });
};