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 = []) {
}
/**
* Helper to validate a store module configuration before it is passed to
* `createStore`.
* Create a store module that can be passed to `createStore`.
*
* @template State
* @template Actions
......@@ -192,9 +191,9 @@ export function createStore(modules, initArgs = [], middleware = []) {
* @param {Module<State,Actions,Selectors,RootSelectors>} config
* @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
// helpful error messages when typechecking if there is something incorrect
// in the configuration.
// in the configuration though.
return config;
}
......@@ -4,7 +4,7 @@
*/
import { actionTypes } from '../util';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
function initialState() {
return {
......@@ -188,7 +188,7 @@ function isSavingAnnotation(state, annotation) {
/** @typedef {import('../../../types/api').Annotation} Annotation */
export default storeModule({
export default createStoreModule({
initialState,
reducers,
namespace: 'activity',
......
......@@ -17,7 +17,7 @@ import { createSelector } from 'reselect';
import * as metadata from '../../helpers/annotation-metadata';
import { countIf, toTrueMap, trueKeys } from '../../util/collections';
import * as util from '../util';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
import route from './route';
......@@ -554,7 +554,7 @@ function savedAnnotations(state) {
});
}
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'annotations',
reducers,
......
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.
......@@ -57,7 +57,7 @@ function getDefaults(state) {
return state;
}
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'defaults',
reducers,
......
import * as util from '../util';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
function initialState(settings) {
return {
......@@ -142,7 +142,7 @@ function directLinkedGroupFetchFailed(state) {
return state.directLinkedGroupFetchFailed;
}
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'directLinked',
reducers,
......
......@@ -2,7 +2,7 @@ import { createSelector } from 'reselect';
import * as metadata from '../../helpers/annotation-metadata';
import * as util from '../util';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
/** @typedef {import('../../../types/api').Annotation} Annotation */
......@@ -187,7 +187,7 @@ const unsavedAnnotations = createSelector(
drafts => drafts.filter(d => !d.annotation.id).map(d => d.annotation)
);
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'drafts',
reducers,
......
import { createSelector } from 'reselect';
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.
......@@ -285,7 +285,7 @@ function hasAppliedFilter(state) {
return !!(state.query || Object.keys(getFilters(state)).length);
}
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'filters',
reducers,
......
......@@ -6,7 +6,7 @@ import {
import shallowEqual from 'shallowequal';
import * as util from '../util';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
/**
* @typedef {import('../../../types/annotator').DocumentMetadata} DocumentMetadata
......@@ -155,7 +155,7 @@ const searchUris = createShallowEqualSelector(
uris => uris
);
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'frames',
reducers,
......
import { createSelector } from 'reselect';
import * as util from '../util';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
import session from './session';
......@@ -197,7 +197,7 @@ const getCurrentlyViewingGroups = createSelector(
}
);
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'groups',
reducers,
......
import { actionTypes } from '../util';
import { replaceURLParams } from '../../util/url';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
function initialState() {
return null;
......@@ -53,7 +53,7 @@ function getLink(state, linkName, params = {}) {
return url;
}
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'links',
reducers,
......
......@@ -9,7 +9,7 @@
import { createSelector } from 'reselect';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
import { actionTypes } from '../util';
import annotations from './annotations';
......@@ -183,7 +183,7 @@ function hasPendingDeletion(state, id) {
return state.pendingDeletions.hasOwnProperty(id);
}
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'realTimeUpdates',
reducers,
......
import { actionTypes } from '../util';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
function initialState() {
return {
......@@ -58,7 +58,7 @@ function routeParams(state) {
return state.params;
}
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'route',
reducers,
......
......@@ -22,7 +22,7 @@ import { createSelector } from 'reselect';
import * as metadata from '../../helpers/annotation-metadata';
import { countIf, trueKeys, toTrueMap } from '../../util/collections';
import * as util from '../util';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
/**
* Default sort keys for each tab.
......@@ -387,7 +387,7 @@ const sortKeys = createSelector(
}
);
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'selection',
reducers,
......
import * as util from '../util';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
/**
* @typedef {import('../../../types/api').Profile} Profile
......@@ -110,7 +110,7 @@ function profile(state) {
return state.profile;
}
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'session',
reducers,
......
......@@ -14,7 +14,7 @@
import * as util from '../util';
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
function initialState() {
return {
......@@ -122,7 +122,7 @@ function isSidebarPanelOpen(state, panelName) {
return state.activePanelName === panelName;
}
export default storeModule({
export default createStoreModule({
namespace: 'sidebarPanels',
initialState,
reducers,
......
import { storeModule } from '../create-store';
import { createStoreModule } from '../create-store';
import * as util from '../util';
......@@ -112,7 +112,7 @@ function hasMessage(state, type, text) {
});
}
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'toastMessages',
reducers,
......
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
......@@ -55,7 +55,7 @@ function hasSidebarOpened(state) {
return state.sidebarHasOpened;
}
export default storeModule({
export default createStoreModule({
initialState,
namespace: 'viewer',
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