From 9c00a2406d61beadebca0437bc160753cad1b2e7 Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Mon, 9 Jan 2017 19:36:40 -0800 Subject: [PATCH] Add new normalizr --- package.json | 2 +- src/redux/actions/ayahs.js | 4 +--- src/redux/actions/bookmarks.js | 3 +-- src/redux/actions/search.js | 3 +-- src/redux/actions/surahs.js | 5 ++--- src/redux/schemas.js | 8 ++++---- src/types/segmentType.js | 5 +---- 7 files changed, 11 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index edeee5074..c20ac9685 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "json-loader": "0.5.4", "morgan": "1.7.0", "node-sass": "4.1.1", - "normalizr": "2.2.1", + "normalizr": "3.0.2", "pretty-error": "2.0.0", "promise": "7.1.1", "proxy-middleware": "0.14.0", diff --git a/src/redux/actions/ayahs.js b/src/redux/actions/ayahs.js index b93f910c6..3dfbfe8b9 100644 --- a/src/redux/actions/ayahs.js +++ b/src/redux/actions/ayahs.js @@ -1,7 +1,5 @@ import { ayahsSchema } from 'redux/schemas'; -import { arrayOf } from 'normalizr'; - import { LOAD, LOAD_SUCCESS, @@ -24,7 +22,7 @@ export function load(id, from, to, options = defaultOptions) { return { types: [LOAD, LOAD_SUCCESS, LOAD_FAIL], - schema: arrayOf(ayahsSchema), + schema: [ayahsSchema], promise: client => client.get(`/v2/surahs/${id}/ayahs`, { params: { from, diff --git a/src/redux/actions/bookmarks.js b/src/redux/actions/bookmarks.js index 47909cba8..536ce5ad3 100644 --- a/src/redux/actions/bookmarks.js +++ b/src/redux/actions/bookmarks.js @@ -1,5 +1,4 @@ import { bookmarksSchema } from 'redux/schemas'; -import { arrayOf } from 'normalizr'; import { LOAD, LOAD_SUCCESS, @@ -19,7 +18,7 @@ export function isLoaded(globalState) { export function load() { return { types: [LOAD, LOAD_SUCCESS, LOAD_FAILURE], - schema: arrayOf(bookmarksSchema), + schema: [bookmarksSchema], promise: client => client.get('/onequran/api/v1/bookmarks') }; } diff --git a/src/redux/actions/search.js b/src/redux/actions/search.js index 352dfeb57..9333c3034 100644 --- a/src/redux/actions/search.js +++ b/src/redux/actions/search.js @@ -1,5 +1,4 @@ import { ayahsSchema } from 'redux/schemas'; -import { arrayOf } from 'normalizr'; import { SEARCH, @@ -10,7 +9,7 @@ import { export function search(params) { return { types: [SEARCH, SEARCH_SUCCESS, SEARCH_FAIL], - schema: { results: arrayOf({ ayah: ayahsSchema }) }, + schema: { results: [{ ayah: ayahsSchema }] }, // TODO: We are doing this because of a weird obj.hasOwnProperty method missing on `params` promise: client => client.get('/v2/search', { params: { q: params.q } }), params diff --git a/src/redux/actions/surahs.js b/src/redux/actions/surahs.js index 3099664e7..ccfbc2951 100644 --- a/src/redux/actions/surahs.js +++ b/src/redux/actions/surahs.js @@ -1,5 +1,4 @@ import { surahsSchema } from 'redux/schemas'; -import { arrayOf } from 'normalizr'; import { LOAD, LOAD_SUCCESS, @@ -13,7 +12,7 @@ import { export function loadAll() { return { types: [LOAD, LOAD_SUCCESS, LOAD_FAIL], - schema: arrayOf(surahsSchema), + schema: [surahsSchema], promise: client => client.get('/v2/surahs') }; } @@ -21,7 +20,7 @@ export function loadAll() { export function load(id) { return { types: [LOAD, LOAD_SUCCESS, LOAD_FAIL], - schema: arrayOf(surahsSchema), + schema: [surahsSchema], promise: client => client.get(`/v2/surahs/${id}`) }; } diff --git a/src/redux/schemas.js b/src/redux/schemas.js index 0a97ba015..a386b5696 100644 --- a/src/redux/schemas.js +++ b/src/redux/schemas.js @@ -1,8 +1,8 @@ -import { Schema } from 'normalizr'; +import { schema } from 'normalizr'; -export const surahsSchema = new Schema('surahs'); -export const ayahsSchema = new Schema('ayahs', { idAttribute: 'ayahKey' }); -export const bookmarksSchema = new Schema('bookmarks', { idAttribute: 'ayahKey' }); +export const surahsSchema = new schema.Entity('surahs'); +export const ayahsSchema = new schema.Entity('ayahs', {}, { idAttribute: 'ayahKey' }); +export const bookmarksSchema = new schema.Entity('bookmarks', {}, { idAttribute: 'ayahKey' }); const schemas = { surahsSchema, diff --git a/src/types/segmentType.js b/src/types/segmentType.js index d564817fb..ca76f885b 100644 --- a/src/types/segmentType.js +++ b/src/types/segmentType.js @@ -6,8 +6,5 @@ export default PropTypes.shape({ endTime: PropTypes.number.isRequired, duration: PropTypes.number.isRequired, })), - intervals: PropTypes.oneOfType([ - PropTypes.array, - PropTypes.object - ]) // TODO: This should be done a better way. + intervals: PropTypes.any // TODO: This should be done a better way. });