Skip to content

Commit

Permalink
fix(Redux): Fix state accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Aug 9, 2016
1 parent c96653f commit a552a8a
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 51 deletions.
21 changes: 4 additions & 17 deletions src/redux/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,16 @@ import actions from './actions';
import reducers from './reducers';
import selectors from './selectors';

const store = createStore(reducers);
export { actions, reducers, selectors };

function dispatch(action) {
export const store = createStore(reducers);

export function dispatch(action) {
var currentAction = action;
while (typeof currentAction === 'function') {
currentAction = action(dispatch, store.getState);
}
return store.dispatch(currentAction);
}

let rootStateAccessor = state => state;
const getRootState = (state) => rootStateAccessor(state);

export function updateVisualizerRootState(fn) {
rootStateAccessor = fn;
}

export default store;

export {
actions,
dispatch,
selectors,
store,
getRootState,
};
10 changes: 5 additions & 5 deletions src/redux/selectors/colors.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { createSelector } from 'reselect';
import { getRootState } from '..';
import access from './stateAccessor';
import { getActiveSourceId, getActiveRepresentation, getActiveRepresentationId } from './proxies';

// ----------------------------------------------------------------------------
// Pure state selection
// ----------------------------------------------------------------------------

export const getPiecewiseMap = state => getRootState(state).colors.piecewiseFunctions;
export const getPresetsImages = state => getRootState(state).colors.presetImages;
export const getScalarBarImages = state => getRootState(state).colors.images;
export const getScalarBarRanges = state => getRootState(state).colors.ranges;
export const getPiecewiseMap = state => access(state).colors.piecewiseFunctions;
export const getPresetsImages = state => access(state).colors.presetImages;
export const getScalarBarImages = state => access(state).colors.images;
export const getScalarBarRanges = state => access(state).colors.ranges;

// ----------------------------------------------------------------------------
// Composite selector
Expand Down
6 changes: 3 additions & 3 deletions src/redux/selectors/files.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createSelector } from 'reselect';
import { getRootState } from '..';
import access from './stateAccessor';

// ----------------------------------------------------------------------------
// Pure state selection
// ----------------------------------------------------------------------------

export const getActivePath = state => getRootState(state).files.activePath;
export const getFileListings = state => getRootState(state).files.listings;
export const getActivePath = state => access(state).files.activePath;
export const getFileListings = state => access(state).files.listings;

// ----------------------------------------------------------------------------
// Composite selector
Expand Down
4 changes: 2 additions & 2 deletions src/redux/selectors/network.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createSelector } from 'reselect';
import { getRootState } from '..';
import access from './stateAccessor';

// ----------------------------------------------------------------------------
// Pure state selection
// ----------------------------------------------------------------------------

export const getPendingRequests = state => getRootState(state).network.pending;
export const getPendingRequests = state => access(state).network.pending;

// ----------------------------------------------------------------------------
// Composite selector
Expand Down
28 changes: 14 additions & 14 deletions src/redux/selectors/proxies.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { createSelector } from 'reselect';
import { getRootState } from '..';
import access from './stateAccessor';

// ----------------------------------------------------------------------------
// Pure state selection
// ----------------------------------------------------------------------------

export const hasSource = state => getRootState(state).active.source && getRootState(state).active.source !== '0';
export const hasSource = state => access(state).active.source && access(state).active.source !== '0';

export const getActiveSourceId = state => getRootState(state).active.source;
export const getProxyMapById = state => getRootState(state).proxies.proxies;
export const getPipeline = state => getRootState(state).proxies.pipeline;
export const getSourceToRepresentationMap = state => getRootState(state).proxies.sourceToRepresentation;
export const getActiveViewId = state => getRootState(state).proxies.pipeline.view;
export const getActiveSourceId = state => access(state).active.source;
export const getProxyMapById = state => access(state).proxies.proxies;
export const getPipeline = state => access(state).proxies.pipeline;
export const getSourceToRepresentationMap = state => access(state).proxies.sourceToRepresentation;
export const getActiveViewId = state => access(state).proxies.pipeline.view;

export const getAvailableSources = state => getRootState(state).proxies.available.sources;
export const getAvailableFilters = state => getRootState(state).proxies.available.filters;
export const getAvailableSources = state => access(state).proxies.available.sources;
export const getAvailableFilters = state => access(state).proxies.available.filters;

export const isSourceCollapsed = state => getRootState(state).ui.collapsablegetRootState(state).Source;
export const isRepresentationCollapsed = state => getRootState(state).ui.collapsablegetRootState(state).Representation;
export const isViewCollapsed = state => getRootState(state).ui.collapsablegetRootState(state).View;
export const isRenderViewSettingsCollapsed = state => getRootState(state).ui.collapsableState['Global Settings'];
export const isSourceCollapsed = state => access(state).ui.collapsableState.Source;
export const isRepresentationCollapsed = state => access(state).ui.collapsableState.Representation;
export const isViewCollapsed = state => access(state).ui.collapsableState.View;
export const isRenderViewSettingsCollapsed = state => access(state).ui.collapsableState['Global Settings'];

export const getRenderViewSettingsProxyId = state => getRootState(state).proxies.settings.RenderViewSettings;
export const getRenderViewSettingsProxyId = state => access(state).proxies.settings.RenderViewSettings;

// ----------------------------------------------------------------------------
// Composite selector
Expand Down
6 changes: 3 additions & 3 deletions src/redux/selectors/save.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getRootState } from '..';
import access from './stateAccessor';

// ----------------------------------------------------------------------------
// Pure state selection
// ----------------------------------------------------------------------------

export const getPaths = state => getRootState(state).save.paths;
export const getStatuses = state => getRootState(state).save.statuses;
export const getPaths = state => access(state).save.paths;
export const getStatuses = state => access(state).save.statuses;
9 changes: 9 additions & 0 deletions src/redux/selectors/stateAccessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let accessor = state => state;

export default function getState(state) {
return accessor(state);
}

export function updateVisualizerStateAccessor(fn) {
accessor = fn;
}
8 changes: 4 additions & 4 deletions src/redux/selectors/time.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getRootState } from '..';
import access from './stateAccessor';

// ----------------------------------------------------------------------------
// Pure state selection
// ----------------------------------------------------------------------------

export const isAnimationPlaying = state => !!getRootState(state).time.playing;
export const getTimeStep = state => getRootState(state).time.index;
export const getTimeValues = state => getRootState(state).time.values;
export const isAnimationPlaying = state => !!access(state).time.playing;
export const getTimeStep = state => access(state).time.index;
export const getTimeValues = state => access(state).time.values;
6 changes: 3 additions & 3 deletions src/redux/selectors/ui.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getRootState } from '..';
import access from './stateAccessor';

// ----------------------------------------------------------------------------
// Pure state selection
// ----------------------------------------------------------------------------

export const getCollapsableState = state => getRootState(state).ui.collapsableState;
export const getVisiblePanel = state => getRootState(state).ui.visiblePanel;
export const getCollapsableState = state => access(state).ui.collapsableState;
export const getVisiblePanel = state => access(state).ui.visiblePanel;

0 comments on commit a552a8a

Please sign in to comment.