How to use the redux-orm.createSelector function in redux-orm

To help you get started, we’ve selected a few redux-orm 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 GiraffeTools / GiraffeTools / frontend / porcupine / selectors / selectors.js View on Github external
orm,
    (state) => state.orm,
    (session) => {
      return session.Sticky.all().toRefArray();
    }
);

export const nodes = createSelector(
    orm,
    (state) => state.orm,
    (session) => {
      return session.Node.all().toRefArray();
    }
);

export const languageNames = createSelector(
    orm,
    (state) => state.orm,
    (session) => {
      return session.Language.all()
          .toModelArray()
          .map((language) => language.name);
    }
);

export const nodesWithParameters = createSelector(
    orm,
    (state) => state.orm,
    (session) => {
      // #TODO: this graph is quite some antipattern to functional
      // programming...
      const nodes = session.Node.all().toModelArray();
github GiraffeTools / GiraffeTools / frontend / porcupine / selectors / selectors.js View on Github external
(session) => {
      return session.Node.all().toRefArray();
    }
);

export const languageNames = createSelector(
    orm,
    (state) => state.orm,
    (session) => {
      return session.Language.all()
          .toModelArray()
          .map((language) => language.name);
    }
);

export const nodesWithParameters = createSelector(
    orm,
    (state) => state.orm,
    (session) => {
      // #TODO: this graph is quite some antipattern to functional
      // programming...
      const nodes = session.Node.all().toModelArray();

      const graph = Graph.getInstance();
      let sorted;
      try {
        const order = GraphAlgorithms.topsort(graph);
        sorted = nodes.sort((a, b) => order.findIndex((id) => id === a.id)
          - order.findIndex((id) => id === b.id));
      } catch (error) {
        // #TODO not sure how to check this:
        // if (error instanceof CycleException) {
github meltyshev / planka / client / src / selectors / next-position.js View on Github external
return (lastItem ? lastItem.position : 0) + Config.POSITION_GAP;
  }

  const prevItem = filteredItems[index - 1];
  const nextItem = filteredItems[index];

  const prevPosition = prevItem ? prevItem.position : 0;

  if (!nextItem) {
    return prevPosition + Config.POSITION_GAP;
  }

  return prevPosition + (nextItem.position - prevPosition) / 2;
};

export const nextBoardPositionSelector = createSelector(
  orm,
  (_, projectId) => projectId,
  (_, __, index) => index,
  (_, __, ___, excludedId) => excludedId,
  ({ Project }, projectId, index, excludedId) => {
    const projectModel = Project.withId(projectId);

    if (!projectModel) {
      return projectModel;
    }

    return nextPosition(projectModel.getOrderedBoardsQuerySet().toRefArray(), index, excludedId);
  },
);

export const nextListPositionSelector = createSelector(
github meltyshev / planka / client / src / selectors / current.js View on Github external
});
        });

        const firstBoard = projectModel.boards.first();
        const firstBoardId = firstBoard && firstBoard.id;

        return {
          ...projectModel.ref,
          notificationsTotal,
          firstBoardId,
        };
      });
  },
);

export const notificationsForCurrentUserSelector = createSelector(
  orm,
  (state) => currentUserIdSelector(state),
  ({ User }, id) => {
    if (!id) {
      return id;
    }

    const userModel = User.withId(id);

    if (!userModel) {
      return userModel;
    }

    return userModel
      .getOrderedUnreadNotificationsQuerySet()
      .toModelArray()
github meltyshev / planka / client / src / selectors / all.js View on Github external
import { createSelector } from 'redux-orm';

import orm from '../orm';
import { currentUserIdSelector } from './current';

export const allUsersSelector = createSelector(
  orm,
  ({ User }) => User.getOrderedUndeletedQuerySet().toRefArray(),
);

export const allUsersExceptCurrentSelector = createSelector(
  orm,
  (state) => currentUserIdSelector(state),
  ({ User }, currentUserId) => User.getOrderedUndeletedQuerySet()
    .exclude({
      id: currentUserId,
    })
    .toRefArray(),
);
github meltyshev / planka / client / src / selectors / current.js View on Github external
({ Card }, id) => {
    if (!id) {
      return id;
    }

    const cardModel = Card.withId(id);

    if (!cardModel) {
      return cardModel;
    }

    return cardModel.labels.toRefArray();
  },
);

export const tasksForCurrentCardSelector = createSelector(
  orm,
  (state) => pathSelector(state).cardId,
  ({ Card }, id) => {
    if (!id) {
      return id;
    }

    const cardModel = Card.withId(id);

    if (!cardModel) {
      return cardModel;
    }

    return cardModel
      .getOrderedTasksQuerySet()
      .toRefArray()
github TylerFisher / full-stack-react / fullstack / staticapp / src / js / app / stores / orm / reducers.js View on Github external
case types.CREATE_OFFICEHOLDERS:
      action.officeholders.map(officeholder => Officeholder.upsert(officeholder));
      break;
    case types.CREATE_PARTIES:
      action.parties.map(party => Party.upsert(party));
      break;
    case types.CREATE_PEOPLE:
      action.people.map(person => Person.upsert(person));
      break;
    default:
      break;
  }
  return session.state;
};

export const officeSelector = createSelector(
  orm,
  state => state.orm,
  session => {
    return session.Office
      .all()
      .toModelArray()
      .map(office => {
        if (!office.division) return null;
        const officeholder = office.officeholderSet.toModelArray()[0];
        if (!officeholder.person) return null;

        const obj = office.serialize();

        return Object.assign({}, obj, {
          division: office.division.serialize(),
          officeholder: {
github ksco / reblog / src / selectors / index.js View on Github external
import { createSelector } from 'reselect';
import { createSelector as ormCreateSelector } from 'redux-orm';

import orm from '../orm';
import { toInteger } from '../utils';

export const ormSelector = state => state.orm;

export const posts = createSelector(
  ormSelector,
  ormCreateSelector(orm, session => {
    return session.Post.all().toModelArray().map(post => ({
        ...post.ref,
        ...post.labels.toRefArray(),
        user: post.user.ref,
    })).sort((a, b) => a.id > b.id ? -1 : 1);
  })
);

export const post = createSelector(
  ormSelector,
  state => toInteger(state.router.params.postId),
  ormCreateSelector(orm, (session, selectedPostId) => {    
    if (session.Post.hasId(selectedPostId)) {
      const post = session.Post.withId(selectedPostId);
      const obj = Object.assign({}, post.ref);
      const labelModels = post.labels.toModelArray();
github meltyshev / planka / client / src / selectors / current.js View on Github external
if (!cardModel) {
      return cardModel;
    }

    return cardModel
      .getOrderedTasksQuerySet()
      .toRefArray()
      .map((task) => ({
        ...task,
        isPersisted: !isLocalId(task.id),
      }));
  },
);

export const actionsForCurrentCardSelector = createSelector(
  orm,
  (state) => pathSelector(state).cardId,
  (state) => currentUserIdSelector(state),
  ({ Card }, id, currentUserId) => {
    if (!id) {
      return id;
    }

    const cardModel = Card.withId(id);

    if (!cardModel) {
      return cardModel;
    }

    return cardModel
      .getOrderedInCardActionsQuerySet()
github hitchcott / spectrum / src / selectors.js View on Github external
};
    });
  }),
);

export const getDefaultAddress = createSelector(
  ormSelector,
  createOrmSelector(schema, (session) => {
    const { defaultAddress } = session.Session.first() || {};
    return defaultAddress && defaultAddress.ref;
  }),
);

export const getSigningModalData = createSelector(
  ormSelector,
  createOrmSelector(schema, session => (session.Session.first() || {}).signingModalData),
);

redux-orm

Simple ORM to manage and query your state trees

MIT
Latest version published 4 years ago

Package Health Score

51 / 100
Full package analysis