How to use the normalizr.schema.Object 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 phandd / spotless / popup / src / actions / search.js View on Github external
idAttribute: track => track.id
})

const playlistSchema = new schema.Entity('playlists', {}, {
  idAttribute: playlist => playlist.id
})

const albumSchema = new schema.Entity('albums', {}, {
  idAttribute: album => album.id
})

// Denormalize state shape so later when we need
// to update one item in result list, we don't
// have to re-render the whole list
// https://redux.js.org/recipes/structuring-reducers/normalizing-state-shape
const searchSchema = new schema.Object({
  tracks: new schema.Object({ items: [trackSchema] }),
  albums: new schema.Object({ items: [albumSchema] }),
  playlists: new schema.Object({ items: [playlistSchema] }),
})

export const doSearch = keyword => dispatch => {
  return dispatch(callApiThunk({
    endpoint: searchEndpointGetters.getSearchEndpoint(keyword),
    schema: searchSchema,
    method: 'GET',
    types: [ actionTypes.SEARCH_REQUEST, actionTypes.SEARCH_SUCCESS, actionTypes.SEARCH_FAILURE ]
  }, { keyword })
  )
}

export const loadMore = resultType => (dispatch, getState) => {
github phandd / spotless / popup / src / actions / search.js View on Github external
})

const playlistSchema = new schema.Entity('playlists', {}, {
  idAttribute: playlist => playlist.id
})

const albumSchema = new schema.Entity('albums', {}, {
  idAttribute: album => album.id
})

// Denormalize state shape so later when we need
// to update one item in result list, we don't
// have to re-render the whole list
// https://redux.js.org/recipes/structuring-reducers/normalizing-state-shape
const searchSchema = new schema.Object({
  tracks: new schema.Object({ items: [trackSchema] }),
  albums: new schema.Object({ items: [albumSchema] }),
  playlists: new schema.Object({ items: [playlistSchema] }),
})

export const doSearch = keyword => dispatch => {
  return dispatch(callApiThunk({
    endpoint: searchEndpointGetters.getSearchEndpoint(keyword),
    schema: searchSchema,
    method: 'GET',
    types: [ actionTypes.SEARCH_REQUEST, actionTypes.SEARCH_SUCCESS, actionTypes.SEARCH_FAILURE ]
  }, { keyword })
  )
}

export const loadMore = resultType => (dispatch, getState) => {
  return dispatch(callApiThunk({
github phandd / spotless / popup / src / actions / search.js View on Github external
const playlistSchema = new schema.Entity('playlists', {}, {
  idAttribute: playlist => playlist.id
})

const albumSchema = new schema.Entity('albums', {}, {
  idAttribute: album => album.id
})

// Denormalize state shape so later when we need
// to update one item in result list, we don't
// have to re-render the whole list
// https://redux.js.org/recipes/structuring-reducers/normalizing-state-shape
const searchSchema = new schema.Object({
  tracks: new schema.Object({ items: [trackSchema] }),
  albums: new schema.Object({ items: [albumSchema] }),
  playlists: new schema.Object({ items: [playlistSchema] }),
})

export const doSearch = keyword => dispatch => {
  return dispatch(callApiThunk({
    endpoint: searchEndpointGetters.getSearchEndpoint(keyword),
    schema: searchSchema,
    method: 'GET',
    types: [ actionTypes.SEARCH_REQUEST, actionTypes.SEARCH_SUCCESS, actionTypes.SEARCH_FAILURE ]
  }, { keyword })
  )
}

export const loadMore = resultType => (dispatch, getState) => {
  return dispatch(callApiThunk({
    endpoint: getState().search.lastResult.result[resultType].next,
github phandd / spotless / popup / src / actions / search.js View on Github external
const playlistSchema = new schema.Entity('playlists', {}, {
  idAttribute: playlist => playlist.id
})

const albumSchema = new schema.Entity('albums', {}, {
  idAttribute: album => album.id
})

// Denormalize state shape so later when we need
// to update one item in result list, we don't
// have to re-render the whole list
// https://redux.js.org/recipes/structuring-reducers/normalizing-state-shape
const searchSchema = new schema.Object({
  tracks: new schema.Object({ items: [trackSchema] }),
  albums: new schema.Object({ items: [albumSchema] }),
  playlists: new schema.Object({ items: [playlistSchema] }),
})

export const doSearch = keyword => dispatch => {
  return dispatch(callApiThunk({
    endpoint: searchEndpointGetters.getSearchEndpoint(keyword),
    schema: searchSchema,
    method: 'GET',
    types: [ actionTypes.SEARCH_REQUEST, actionTypes.SEARCH_SUCCESS, actionTypes.SEARCH_FAILURE ]
  }, { keyword })
  )
}

export const loadMore = resultType => (dispatch, getState) => {
  return dispatch(callApiThunk({
    endpoint: getState().search.lastResult.result[resultType].next,
    schema: searchSchema,
github goodmind / treact / packages / treact / src / app / store / modules / media / entities.ts View on Github external
export const document = new schema.Entity('documents', {
  thumb: new schema.Union(metaPhotoSize, '_'),
}, {
  processStrategy: processDoc,
  idAttribute: pipe(prop('id'), e => +e),
})

const photo = new schema.Entity('photos', {
  sizes: new schema.Array(metaPhotoSize, '_'),
}, {
  processStrategy: processPhoto,
  idAttribute: pipe(prop('id'), e => +e),
})

const webpage = new schema.Object({
  document,
  photo,
})

const messageMediaDocument = new schema.Entity('media', {
  document,
}, {
  processStrategy: value => {
    const { type } = processDoc(value.document)
    return { type, ...value }
  },
  idAttribute: (_, parent) => path(['id'], parent),
})

const messageMediaPhoto = new schema.Entity('media', {
  photo,
github Superjo149 / auryo / src / common / api / fetchPersonalised.ts View on Github external
export default async function fetchPersonalised(url: string): Promise<{
    json: JsonResponse,
    normalized: {
        entities: NormalizedEntities;
        result: Array;
    }
}> {
    try {
        const json = await fetchToJson(url);

        const collection = json.collection.filter((t) => t.urn.indexOf('chart') === -1);

        return ({
            normalized: normalize(collection, new schema.Array(new schema.Object({
                system_playlists: new schema.Array(playlistSchema),
                playlists: new schema.Array(playlistSchema)
            }))),
            json
        });

    } catch (err) {
        throw err;
    }
}