How to use the normalizr.arrayOf 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 supercomments / supercomments / src / effects / redditAPI.js View on Github external
[Sort.Oldest]: 'old'
};

const htmlEntitiesDecoder = new XmlEntities();

const ApiSchema = {
  [Entities.Comment]: new Schema(Entities.Comment),
  [Entities.Post]: new Schema(Entities.Post)
};

ApiSchema[Entities.Comment].define({
  replies: arrayOf(ApiSchema[Entities.Comment])
});

ApiSchema[Entities.Post].define({
  comments: arrayOf(ApiSchema[Entities.Comment])
});

// TODO: proper snoocore init
const reddit = new Snoocore({
  userAgent: 'supercomments',
  oauth: {
    type: 'implicit',
    key: 'CRcRenqfbTCNLw',
    redirectUri: 'http://localhost:3000',
    scope: ['identity', 'read', 'submit', 'vote']
  }
});

const mapRedditReplies = replies => replies.map(({ data }) => ({
  id: data.id,
  name: data.name,
github devsnd / cherrymusic / res / react-client / src / redux / modules / CherryMusicApi.js View on Github external
[DIRECTORY_LOADED]: (state, action) => {
    const {path, collections, tracks, compacts } = action.payload;
    const normCollection = normalize(collections, arrayOf(collectionSchema));
    const normCompacts = normalize(compacts, arrayOf(compactSchema));
    const normTracks = normalize(
      // insert metaDataLoading State into each track
      tracks.map((track) => {
        track.metadataLoadingState = MetaDataLoadingStates.idle;
        return track;
      }),
      arrayOf(trackSchema)
    );
    const receivedEntities = {
      ...normCollection.entities,
      ...normTracks.entities,
      ...normCompacts.entities,
    };
    const mergedEntities = mergeEntities(state.entities, receivedEntities);

    return {
github hackoregon / btc-frontend-2016-ReactRedux / src / client / api / serverApi.js View on Github external
});
const contributions = ({
  owner: campaign,
  individual: arrayOf(indivContribution),
  business: arrayOf(businessContribution),
  pac: arrayOf(pacContribution),
  states: arrayOf(stateContribution)
});
campaign.define({
  listByName: valuesOf(campaign, {
    schemaAttribute: 'candidateName'
  })
});
const search = new Schema('searches');
search.define({
  list: arrayOf(campaign)
});
// contribution.define({
//   owner: campaign
// });
indivContribution.define({
  owner: campaign,
  listByType: valuesOf(transaction, {
    schemaAttribute: 'bookType'
  })
});
donor.define({
  owner: transaction,
  listByName: valuesOf(transaction, {
    schemaAttribute: 'contributorPayee'
  }),
  relationships: valuesOf(campaign)
github LucasYuNju / leanote-desktop-lite / src / actions / NoteActions.js View on Github external
return async (dispatch, getState) => {
    while (true) {
      const action = await dispatch({
        types: [null, types.GET_NOTES_SUCCESS, null],
        url: 'note/getSyncNotes',
        query: {
          afterUsn: getState().user.localUsn.note,
          maxEntry: 100,
        },
        schema: arrayOf(noteSchema),
      });
      // Dispatch all networks at the same time will cause 404 error.
      action.payload.result
        .map(noteId => action.payload.entities.notes[noteId])
        .filter(note => !note.isDeleted && !note.isTrash)
        .reduce((promise, note) => {
          return promise.then(() => {
            return dispatch(fetchNoteAndContent(note.noteId));
          });
        }, Promise.resolve());
      if (action.payload.result.length === 0) {
        break;
      }
    }
  }
}
github fraserxu / soundredux-native / src / actions / songs.js View on Github external
.then(json => {
        const songs = json.filter(song => songTitle !== song.title)
        const normalized = normalize(songs, arrayOf(songSchema))
        dispatch(receiveSongs(normalized.result, normalized.entities, songTitle))
      })
      .catch(error => console.log(error))
github ubyssey / dispatch / dispatch / static / manager / src / js / actions / TemplatesActions.js View on Github external
.then(function(json) {
        return {
          count: json.count,
          results: normalize(json.results, arrayOf(templateSchema))
        }
      })
  }
github dremio / dremio-oss / dac / ui / src / schemas / space.js View on Github external
* See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { Schema, arrayOf } from 'normalizr';
import { ENTITY_TYPES } from '@app/constants/Constants';

import dataset from './dataset';
import file from './file';
import folder from './folder';
import physicalDataset from './physicalDataset';

const space = new Schema(ENTITY_TYPES.space);

space.define({
  contents: {
    datasets: arrayOf(dataset),
    files: arrayOf(file),
    folders: arrayOf(folder),
    physicalDatasets: arrayOf(physicalDataset)
  }
});

export default space;
github vincent178 / ruby-china-mobile / common / constants / schema.js View on Github external
topic.define({
  user: user
});

reply.define({
  user: user
});

notification.define({
  actor: user,
  topic: topic,
  reply: reply
});

user.define({
  topics: arrayOf(topic),
  replies: arrayOf(reply),
  followers: arrayOf(user),
  following: arrayOf(user)
});

export const topicSchema = topic;
export const userSchema = user;
export const replySchema = reply;
export const notificationSchema = notification;
github amitava82 / radiole / client / scripts / redux / schemas.js View on Github external
*/
import { Schema, arrayOf, normalize } from 'normalizr'

const playlistSchema = new Schema('playlists', {
    idAttribute: 'id'
});

const watchlistSchema = new Schema('watchlist', {
    idAttribute: '_id'
});



export default {
    PLAYLIST: playlistSchema,
    PLAYLIST_ARRAY: arrayOf(playlistSchema),
    WATCHLIST: watchlistSchema,
    WATCHLIST_ARRAY: arrayOf(watchlistSchema)
};
github Nebo15 / annon.web / app / common / redux / plugins.js View on Github external
      json => normalize(json.data, arrayOf(pluginsSchema))
    ),