Permalink
Browse files

Use a selector to have only a single Session instance per state update

  • Loading branch information...
markerikson committed Jan 22, 2017
1 parent 13c657c commit 42693a331fee1ff73594ff18e3833415655f7262
@@ -0,0 +1,10 @@
import {createSelector} from "reselect";
import schema from "app/schema";
export const selectEntities = state => state.entities;
export const getEntitiesSession = createSelector(
selectEntities,
entities => schema.from(entities)
);
@@ -2,7 +2,7 @@ import React from "react";
import {connect} from "react-redux";
import {Form} from "semantic-ui-react";
import schema from "app/schema";
import {getEntitiesSession} from "features/entities/entitySelectors";
import {getWeightClass, selectCurrentMech} from "../mechSelectors";
@@ -12,7 +12,7 @@ const mapState = (state) => {
const currentMech = selectCurrentMech(state);
const session = schema.from(state.entities);
const session = getEntitiesSession(state);
const {Mech} = session;
if(Mech.hasId(currentMech)) {
@@ -5,14 +5,14 @@ import {Table} from "semantic-ui-react";
import MechsListHeader from "./MechsListHeader";
import MechsListRow from "./MechsListRow";
import schema from "app/schema";
import {getEntitiesSession} from "features/entities/entitySelectors";
import {selectMech} from "../mechsActions";
import {selectCurrentMech} from "../mechSelectors";
const mapState = (state) => {
const session = schema.from(state.entities);
const session = getEntitiesSession(state);
const {Mech} = session;
const mechs = Mech.all().withModels.map(mechModel => mechModel.getId());
@@ -5,10 +5,10 @@ import {Table} from "semantic-ui-react";
import {getWeightClass} from "../mechSelectors";
import schema from "app/schema";
import {getEntitiesSession} from "features/entities/entitySelectors";
const mapState = (state, ownProps) => {
const session = schema.from(state.entities);
const session = getEntitiesSession(state);
const {Mech} = session;
let mech;
@@ -2,7 +2,7 @@ import React, {Component} from "react";
import {connect} from "react-redux";
import {Form, Dropdown, Grid, Button} from "semantic-ui-react";
import schema from "app/schema";
import {getEntitiesSession} from "features/entities/entitySelectors";
import FormEditWrapper from "common/components/FormEditWrapper";
@@ -49,7 +49,7 @@ const mapState = (state) => {
const currentPilot = selectCurrentPilot(state);
const session = schema.from(state.entities);
const session = getEntitiesSession(state);
const {Pilot} = session;
if(Pilot.hasId(currentPilot)) {
@@ -5,7 +5,7 @@ import {Table} from "semantic-ui-react";
import PilotsListHeader from "./PilotsListHeader";
import PilotsListRow from "./PilotsListRow";
import schema from "app/schema";
import {getEntitiesSession} from "features/entities/entitySelectors";
import {selectPilot} from "../pilotsActions";
import {selectCurrentPilot} from "../pilotsSelectors";
@@ -14,7 +14,7 @@ import {selectCurrentPilot} from "../pilotsSelectors";
const mapState = (state) => {
// Create a Redux-ORM Session from our "entities" slice, which
// contains the "tables" for each model type
const session = schema.from(state.entities);
const session = getEntitiesSession(state);
// Retrieve the model class that we need. Each Session
// specifically "binds" model classes to itself, so that
@@ -3,10 +3,10 @@ import {connect} from "react-redux";
import {Table} from "semantic-ui-react";
import _ from "lodash";
import schema from "app/schema";
import {getEntitiesSession} from "features/entities/entitySelectors";
const mapState = (state, ownProps) => {
const session = schema.from(state.entities);
const session = getEntitiesSession(state);
const {Pilot} = session;
let pilot;

0 comments on commit 42693a3

Please sign in to comment.