Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) => {
})
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({
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,
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,
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,
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;
}
}