Commit b015df45 authored by Robert Knight's avatar Robert Knight

Rename `storeModule` => `createStoreModule`

This function was originally written as a helper to enable us to enable
TypeScript to generate more useful errors if a store module had the
wrong structure. However it also provides a place that we can do runtime
checks / normalization of store modules etc.

Rename the function and update the documentation to make it clear that
this is the correct way to define a store module.
parent a50bf888
...@@ -182,8 +182,7 @@ export function createStore(modules, initArgs = [], middleware = []) { ...@@ -182,8 +182,7 @@ export function createStore(modules, initArgs = [], middleware = []) {
} }
/** /**
* Helper to validate a store module configuration before it is passed to * Create a store module that can be passed to `createStore`.
* `createStore`.
* *
* @template State * @template State
* @template Actions * @template Actions
...@@ -192,9 +191,9 @@ export function createStore(modules, initArgs = [], middleware = []) { ...@@ -192,9 +191,9 @@ export function createStore(modules, initArgs = [], middleware = []) {
* @param {Module<State,Actions,Selectors,RootSelectors>} config * @param {Module<State,Actions,Selectors,RootSelectors>} config
* @return {Module<State,Actions,Selectors,RootSelectors>} * @return {Module<State,Actions,Selectors,RootSelectors>}
*/ */
export function storeModule(config) { export function createStoreModule(config) {
// This helper doesn't currently do anything at runtime. It does ensure more // This helper doesn't currently do anything at runtime. It does ensure more
// helpful error messages when typechecking if there is something incorrect // helpful error messages when typechecking if there is something incorrect
// in the configuration. // in the configuration though.
return config; return config;
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
*/ */
import { actionTypes } from '../util'; import { actionTypes } from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
function initialState() { function initialState() {
return { return {
...@@ -188,7 +188,7 @@ function isSavingAnnotation(state, annotation) { ...@@ -188,7 +188,7 @@ function isSavingAnnotation(state, annotation) {
/** @typedef {import('../../../types/api').Annotation} Annotation */ /** @typedef {import('../../../types/api').Annotation} Annotation */
export default storeModule({ export default createStoreModule({
initialState, initialState,
reducers, reducers,
namespace: 'activity', namespace: 'activity',
......
...@@ -17,7 +17,7 @@ import { createSelector } from 'reselect'; ...@@ -17,7 +17,7 @@ import { createSelector } from 'reselect';
import * as metadata from '../../helpers/annotation-metadata'; import * as metadata from '../../helpers/annotation-metadata';
import { countIf, toTrueMap, trueKeys } from '../../util/collections'; import { countIf, toTrueMap, trueKeys } from '../../util/collections';
import * as util from '../util'; import * as util from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
import route from './route'; import route from './route';
...@@ -554,7 +554,7 @@ function savedAnnotations(state) { ...@@ -554,7 +554,7 @@ function savedAnnotations(state) {
}); });
} }
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'annotations', namespace: 'annotations',
reducers, reducers,
......
import * as util from '../util'; import * as util from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
/** /**
* A store module for managing client-side user-convenience defaults. * A store module for managing client-side user-convenience defaults.
...@@ -57,7 +57,7 @@ function getDefaults(state) { ...@@ -57,7 +57,7 @@ function getDefaults(state) {
return state; return state;
} }
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'defaults', namespace: 'defaults',
reducers, reducers,
......
import * as util from '../util'; import * as util from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
function initialState(settings) { function initialState(settings) {
return { return {
...@@ -142,7 +142,7 @@ function directLinkedGroupFetchFailed(state) { ...@@ -142,7 +142,7 @@ function directLinkedGroupFetchFailed(state) {
return state.directLinkedGroupFetchFailed; return state.directLinkedGroupFetchFailed;
} }
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'directLinked', namespace: 'directLinked',
reducers, reducers,
......
...@@ -2,7 +2,7 @@ import { createSelector } from 'reselect'; ...@@ -2,7 +2,7 @@ import { createSelector } from 'reselect';
import * as metadata from '../../helpers/annotation-metadata'; import * as metadata from '../../helpers/annotation-metadata';
import * as util from '../util'; import * as util from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
/** @typedef {import('../../../types/api').Annotation} Annotation */ /** @typedef {import('../../../types/api').Annotation} Annotation */
...@@ -187,7 +187,7 @@ const unsavedAnnotations = createSelector( ...@@ -187,7 +187,7 @@ const unsavedAnnotations = createSelector(
drafts => drafts.filter(d => !d.annotation.id).map(d => d.annotation) drafts => drafts.filter(d => !d.annotation.id).map(d => d.annotation)
); );
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'drafts', namespace: 'drafts',
reducers, reducers,
......
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { actionTypes } from '../util'; import { actionTypes } from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
/** /**
* Manage state pertaining to the filtering of annotations in the UI. * Manage state pertaining to the filtering of annotations in the UI.
...@@ -285,7 +285,7 @@ function hasAppliedFilter(state) { ...@@ -285,7 +285,7 @@ function hasAppliedFilter(state) {
return !!(state.query || Object.keys(getFilters(state)).length); return !!(state.query || Object.keys(getFilters(state)).length);
} }
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'filters', namespace: 'filters',
reducers, reducers,
......
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
import shallowEqual from 'shallowequal'; import shallowEqual from 'shallowequal';
import * as util from '../util'; import * as util from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
/** /**
* @typedef {import('../../../types/annotator').DocumentMetadata} DocumentMetadata * @typedef {import('../../../types/annotator').DocumentMetadata} DocumentMetadata
...@@ -155,7 +155,7 @@ const searchUris = createShallowEqualSelector( ...@@ -155,7 +155,7 @@ const searchUris = createShallowEqualSelector(
uris => uris uris => uris
); );
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'frames', namespace: 'frames',
reducers, reducers,
......
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import * as util from '../util'; import * as util from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
import session from './session'; import session from './session';
...@@ -197,7 +197,7 @@ const getCurrentlyViewingGroups = createSelector( ...@@ -197,7 +197,7 @@ const getCurrentlyViewingGroups = createSelector(
} }
); );
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'groups', namespace: 'groups',
reducers, reducers,
......
import { actionTypes } from '../util'; import { actionTypes } from '../util';
import { replaceURLParams } from '../../util/url'; import { replaceURLParams } from '../../util/url';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
function initialState() { function initialState() {
return null; return null;
...@@ -53,7 +53,7 @@ function getLink(state, linkName, params = {}) { ...@@ -53,7 +53,7 @@ function getLink(state, linkName, params = {}) {
return url; return url;
} }
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'links', namespace: 'links',
reducers, reducers,
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
import { actionTypes } from '../util'; import { actionTypes } from '../util';
import annotations from './annotations'; import annotations from './annotations';
...@@ -183,7 +183,7 @@ function hasPendingDeletion(state, id) { ...@@ -183,7 +183,7 @@ function hasPendingDeletion(state, id) {
return state.pendingDeletions.hasOwnProperty(id); return state.pendingDeletions.hasOwnProperty(id);
} }
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'realTimeUpdates', namespace: 'realTimeUpdates',
reducers, reducers,
......
import { actionTypes } from '../util'; import { actionTypes } from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
function initialState() { function initialState() {
return { return {
...@@ -58,7 +58,7 @@ function routeParams(state) { ...@@ -58,7 +58,7 @@ function routeParams(state) {
return state.params; return state.params;
} }
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'route', namespace: 'route',
reducers, reducers,
......
...@@ -22,7 +22,7 @@ import { createSelector } from 'reselect'; ...@@ -22,7 +22,7 @@ import { createSelector } from 'reselect';
import * as metadata from '../../helpers/annotation-metadata'; import * as metadata from '../../helpers/annotation-metadata';
import { countIf, trueKeys, toTrueMap } from '../../util/collections'; import { countIf, trueKeys, toTrueMap } from '../../util/collections';
import * as util from '../util'; import * as util from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
/** /**
* Default sort keys for each tab. * Default sort keys for each tab.
...@@ -387,7 +387,7 @@ const sortKeys = createSelector( ...@@ -387,7 +387,7 @@ const sortKeys = createSelector(
} }
); );
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'selection', namespace: 'selection',
reducers, reducers,
......
import * as util from '../util'; import * as util from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
/** /**
* @typedef {import('../../../types/api').Profile} Profile * @typedef {import('../../../types/api').Profile} Profile
...@@ -110,7 +110,7 @@ function profile(state) { ...@@ -110,7 +110,7 @@ function profile(state) {
return state.profile; return state.profile;
} }
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'session', namespace: 'session',
reducers, reducers,
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
import * as util from '../util'; import * as util from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
function initialState() { function initialState() {
return { return {
...@@ -122,7 +122,7 @@ function isSidebarPanelOpen(state, panelName) { ...@@ -122,7 +122,7 @@ function isSidebarPanelOpen(state, panelName) {
return state.activePanelName === panelName; return state.activePanelName === panelName;
} }
export default storeModule({ export default createStoreModule({
namespace: 'sidebarPanels', namespace: 'sidebarPanels',
initialState, initialState,
reducers, reducers,
......
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
import * as util from '../util'; import * as util from '../util';
...@@ -112,7 +112,7 @@ function hasMessage(state, type, text) { ...@@ -112,7 +112,7 @@ function hasMessage(state, type, text) {
}); });
} }
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'toastMessages', namespace: 'toastMessages',
reducers, reducers,
......
import * as util from '../util'; import * as util from '../util';
import { storeModule } from '../create-store'; import { createStoreModule } from '../create-store';
/** /**
* This module defines actions and state related to the display mode of the * This module defines actions and state related to the display mode of the
...@@ -55,7 +55,7 @@ function hasSidebarOpened(state) { ...@@ -55,7 +55,7 @@ function hasSidebarOpened(state) {
return state.sidebarHasOpened; return state.sidebarHasOpened;
} }
export default storeModule({ export default createStoreModule({
initialState, initialState,
namespace: 'viewer', namespace: 'viewer',
reducers, reducers,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment