Commit 4ca56948 authored by Robert Knight's avatar Robert Knight

Align store module naming with Redux terminology

Rename several fields of the configuration object for store modules to
better align with the associated Redux concepts. This should make it
easier for newcomers to the code to understand it if they already have
some familiarity with Redux.

 - Rename the `init` function to `initialState`
 - Rename the `update` map to `reducers`
 - Rename the `actions` map to `actionCreators`
parent 7563a60c
...@@ -37,14 +37,14 @@ import { createReducer, bindSelectors } from './util'; ...@@ -37,14 +37,14 @@ import { createReducer, bindSelectors } from './util';
* @template {object} Selectors * @template {object} Selectors
* @template {object} RootSelectors * @template {object} RootSelectors
* @typedef Module * @typedef Module
* @prop {(...args: any[]) => State} init - * @prop {(...args: any[]) => State} initialState -
* Function that returns the initial state for the module * Function that returns the initial state for the module
* @prop {string} namespace - * @prop {string} namespace -
* The key under which this module's state will live in the store's root state * The key under which this module's state will live in the store's root state
* @prop {Reducers<State>} update - * @prop {Reducers<State>} reducers -
* Map of action types to "reducer" functions that process an action and return * Map of action types to "reducer" functions that process an action and return
* the changes to the state * the changes to the state
* @prop {Actions} actions * @prop {Actions} actionCreators
* Object containing action creator functions * Object containing action creator functions
* @prop {Selectors} selectors * @prop {Selectors} selectors
* Object containing selector functions * Object containing selector functions
...@@ -99,7 +99,7 @@ import { createReducer, bindSelectors } from './util'; ...@@ -99,7 +99,7 @@ import { createReducer, bindSelectors } from './util';
* from that state. * from that state.
* *
* In addition to the standard Redux store interface, the returned store also exposes * In addition to the standard Redux store interface, the returned store also exposes
* each action and selector from the input modules as a method. For example, if * each action creator and selector from the input modules as a method. For example, if
* a store is created from a module that has a `getWidget(<id>)` selector and * a store is created from a module that has a `getWidget(<id>)` selector and
* an `addWidget(<object>)` action, a consumer would use `store.getWidget(<id>)` * an `addWidget(<object>)` action, a consumer would use `store.getWidget(<id>)`
* to fetch an item and `store.addWidget(<object>)` to dispatch an action that * to fetch an item and `store.addWidget(<object>)` to dispatch an action that
...@@ -112,7 +112,7 @@ import { createReducer, bindSelectors } from './util'; ...@@ -112,7 +112,7 @@ import { createReducer, bindSelectors } from './util';
* what store state a component depends upon and re-render when it changes. * what store state a component depends upon and re-render when it changes.
* *
* @param {Module<any,any,any,any>[]} modules * @param {Module<any,any,any,any>[]} modules
* @param {any[]} [initArgs] - Arguments to pass to each state module's `init` function * @param {any[]} [initArgs] - Arguments to pass to each state module's `initialState` function
* @param {any[]} [middleware] - List of additional Redux middlewares to use * @param {any[]} [middleware] - List of additional Redux middlewares to use
* @return Store<any,any,any> * @return Store<any,any,any>
*/ */
...@@ -137,9 +137,9 @@ export function createStore(modules, initArgs = [], middleware = []) { ...@@ -137,9 +137,9 @@ export function createStore(modules, initArgs = [], middleware = []) {
// //
modules.forEach(module => { modules.forEach(module => {
if (module.namespace) { if (module.namespace) {
initialState[module.namespace] = module.init(...initArgs); initialState[module.namespace] = module.initialState(...initArgs);
allReducers[module.namespace] = createReducer(module.update); allReducers[module.namespace] = createReducer(module.reducers);
allSelectors[module.namespace] = { allSelectors[module.namespace] = {
selectors: module.selectors, selectors: module.selectors,
rootSelectors: module.rootSelectors || {}, rootSelectors: module.rootSelectors || {},
...@@ -172,7 +172,7 @@ export function createStore(modules, initArgs = [], middleware = []) { ...@@ -172,7 +172,7 @@ export function createStore(modules, initArgs = [], middleware = []) {
const store = redux.createStore(reducer, initialState, enhancer); const store = redux.createStore(reducer, initialState, enhancer);
// Add actions and selectors as methods to the store. // Add actions and selectors as methods to the store.
const actions = Object.assign({}, ...modules.map(m => m.actions)); const actions = Object.assign({}, ...modules.map(m => m.actionCreators));
const boundActions = redux.bindActionCreators(actions, store.dispatch); const boundActions = redux.bindActionCreators(actions, store.dispatch);
const boundSelectors = bindSelectors(allSelectors, store.getState); const boundSelectors = bindSelectors(allSelectors, store.getState);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import { actionTypes } from '../util'; import { actionTypes } from '../util';
import { storeModule } from '../create-store'; import { storeModule } from '../create-store';
function init() { function initialState() {
return { return {
/** /**
* Annotation `$tag`s that correspond to annotations with active API requests * Annotation `$tag`s that correspond to annotations with active API requests
...@@ -32,7 +32,7 @@ function init() { ...@@ -32,7 +32,7 @@ function init() {
}; };
} }
const update = { const reducers = {
API_REQUEST_STARTED(state) { API_REQUEST_STARTED(state) {
return { return {
...state, ...state,
...@@ -107,7 +107,7 @@ const update = { ...@@ -107,7 +107,7 @@ const update = {
}, },
}; };
const actions = actionTypes(update); const actions = actionTypes(reducers);
/** Action Creators */ /** Action Creators */
...@@ -189,11 +189,11 @@ function isSavingAnnotation(state, annotation) { ...@@ -189,11 +189,11 @@ function isSavingAnnotation(state, annotation) {
/** @typedef {import('../../../types/api').Annotation} Annotation */ /** @typedef {import('../../../types/api').Annotation} Annotation */
export default storeModule({ export default storeModule({
init, initialState,
update, reducers,
namespace: 'activity', namespace: 'activity',
actions: { actionCreators: {
annotationFetchStarted, annotationFetchStarted,
annotationFetchFinished, annotationFetchFinished,
annotationSaveStarted, annotationSaveStarted,
......
...@@ -89,7 +89,7 @@ function initializeAnnotation(annotation, tag) { ...@@ -89,7 +89,7 @@ function initializeAnnotation(annotation, tag) {
}); });
} }
function init() { function initialState() {
return { return {
/** @type {Annotation[]} */ /** @type {Annotation[]} */
annotations: [], annotations: [],
...@@ -105,7 +105,7 @@ function init() { ...@@ -105,7 +105,7 @@ function init() {
}; };
} }
const update = { const reducers = {
ADD_ANNOTATIONS: function (state, action) { ADD_ANNOTATIONS: function (state, action) {
const updatedIDs = {}; const updatedIDs = {};
const updatedTags = {}; const updatedTags = {};
...@@ -232,7 +232,7 @@ const update = { ...@@ -232,7 +232,7 @@ const update = {
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
/* Action creators */ /* Action creators */
...@@ -555,10 +555,10 @@ function savedAnnotations(state) { ...@@ -555,10 +555,10 @@ function savedAnnotations(state) {
} }
export default storeModule({ export default storeModule({
init: init, initialState,
namespace: 'annotations', namespace: 'annotations',
update: update, reducers,
actions: { actionCreators: {
addAnnotations, addAnnotations,
clearAnnotations, clearAnnotations,
focusAnnotations, focusAnnotations,
......
...@@ -16,7 +16,7 @@ import { storeModule } from '../create-store'; ...@@ -16,7 +16,7 @@ import { storeModule } from '../create-store';
* `persistedDefaults` service. * `persistedDefaults` service.
*/ */
function init() { function initialState() {
/** /**
* Note that the persisted presence of any of these defaults cannot be * Note that the persisted presence of any of these defaults cannot be
* guaranteed, so consumers of said defaults should be prepared to handle * guaranteed, so consumers of said defaults should be prepared to handle
...@@ -29,13 +29,13 @@ function init() { ...@@ -29,13 +29,13 @@ function init() {
}; };
} }
const update = { const reducers = {
SET_DEFAULT: function (state, action) { SET_DEFAULT: function (state, action) {
return { [action.defaultKey]: action.value }; return { [action.defaultKey]: action.value };
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
function setDefault(defaultKey, value) { function setDefault(defaultKey, value) {
return { type: actions.SET_DEFAULT, defaultKey: defaultKey, value: value }; return { type: actions.SET_DEFAULT, defaultKey: defaultKey, value: value };
...@@ -58,10 +58,10 @@ function getDefaults(state) { ...@@ -58,10 +58,10 @@ function getDefaults(state) {
} }
export default storeModule({ export default storeModule({
init, initialState,
namespace: 'defaults', namespace: 'defaults',
update, reducers,
actions: { actionCreators: {
setDefault, setDefault,
}, },
selectors: { selectors: {
......
...@@ -2,7 +2,7 @@ import * as util from '../util'; ...@@ -2,7 +2,7 @@ import * as util from '../util';
import { storeModule } from '../create-store'; import { storeModule } from '../create-store';
function init(settings) { function initialState(settings) {
return { return {
/** /**
* The ID of the direct-linked group. * The ID of the direct-linked group.
...@@ -42,7 +42,7 @@ function init(settings) { ...@@ -42,7 +42,7 @@ function init(settings) {
}; };
} }
const update = { const reducers = {
UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED(state, action) { UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED(state, action) {
return { return {
directLinkedGroupFetchFailed: action.directLinkedGroupFetchFailed, directLinkedGroupFetchFailed: action.directLinkedGroupFetchFailed,
...@@ -73,7 +73,7 @@ const update = { ...@@ -73,7 +73,7 @@ const update = {
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
/** /**
* Set the direct linked group id. * Set the direct linked group id.
...@@ -143,10 +143,10 @@ function directLinkedGroupFetchFailed(state) { ...@@ -143,10 +143,10 @@ function directLinkedGroupFetchFailed(state) {
} }
export default storeModule({ export default storeModule({
init, initialState,
namespace: 'directLinked', namespace: 'directLinked',
update, reducers,
actions: { actionCreators: {
setDirectLinkedGroupFetchFailed, setDirectLinkedGroupFetchFailed,
setDirectLinkedGroupId, setDirectLinkedGroupId,
setDirectLinkedAnnotationId, setDirectLinkedAnnotationId,
......
...@@ -11,7 +11,7 @@ import { storeModule } from '../create-store'; ...@@ -11,7 +11,7 @@ import { storeModule } from '../create-store';
* existing annotations. * existing annotations.
*/ */
function init() { function initialState() {
return []; return [];
} }
...@@ -57,7 +57,7 @@ export class Draft { ...@@ -57,7 +57,7 @@ export class Draft {
/* Reducer */ /* Reducer */
const update = { const reducers = {
DISCARD_ALL_DRAFTS: function () { DISCARD_ALL_DRAFTS: function () {
return []; return [];
}, },
...@@ -77,7 +77,7 @@ const update = { ...@@ -77,7 +77,7 @@ const update = {
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
/* Actions */ /* Actions */
...@@ -188,10 +188,10 @@ const unsavedAnnotations = createSelector( ...@@ -188,10 +188,10 @@ const unsavedAnnotations = createSelector(
); );
export default storeModule({ export default storeModule({
init, initialState,
namespace: 'drafts', namespace: 'drafts',
update, reducers,
actions: { actionCreators: {
createDraft, createDraft,
deleteNewAndEmptyDrafts, deleteNewAndEmptyDrafts,
discardAllDrafts, discardAllDrafts,
......
...@@ -56,7 +56,7 @@ import { storeModule } from '../create-store'; ...@@ -56,7 +56,7 @@ import { storeModule } from '../create-store';
* @prop {string} displayName * @prop {string} displayName
*/ */
function init(settings) { function initialState(settings) {
const focusConfig = settings.focus || {}; const focusConfig = settings.focus || {};
return { return {
/** /**
...@@ -105,7 +105,7 @@ function focusFiltersFromConfig(focusConfig) { ...@@ -105,7 +105,7 @@ function focusFiltersFromConfig(focusConfig) {
}; };
} }
const update = { const reducers = {
CHANGE_FOCUS_MODE_USER: function (state, action) { CHANGE_FOCUS_MODE_USER: function (state, action) {
if (isValidFocusConfig({ user: action.user })) { if (isValidFocusConfig({ user: action.user })) {
return { return {
...@@ -152,7 +152,7 @@ const update = { ...@@ -152,7 +152,7 @@ const update = {
}, },
}; };
const actions = actionTypes(update); const actions = actionTypes(reducers);
// Action creators // Action creators
...@@ -286,10 +286,10 @@ function hasAppliedFilter(state) { ...@@ -286,10 +286,10 @@ function hasAppliedFilter(state) {
} }
export default storeModule({ export default storeModule({
init, initialState,
namespace: 'filters', namespace: 'filters',
update, reducers,
actions: { actionCreators: {
changeFocusModeUser, changeFocusModeUser,
setFilter, setFilter,
setFilterQuery, setFilterQuery,
......
...@@ -20,12 +20,12 @@ import { storeModule } from '../create-store'; ...@@ -20,12 +20,12 @@ import { storeModule } from '../create-store';
* @prop {string} uri - Current primary URI of the document being displayed * @prop {string} uri - Current primary URI of the document being displayed
*/ */
function init() { function initialState() {
// The list of frames connected to the sidebar app // The list of frames connected to the sidebar app
return []; return [];
} }
const update = { const reducers = {
CONNECT_FRAME: function (state, action) { CONNECT_FRAME: function (state, action) {
return [...state, action.frame]; return [...state, action.frame];
}, },
...@@ -49,7 +49,7 @@ const update = { ...@@ -49,7 +49,7 @@ const update = {
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
/** /**
* Add a frame to the list of frames currently connected to the sidebar app. * Add a frame to the list of frames currently connected to the sidebar app.
...@@ -156,11 +156,11 @@ const searchUris = createShallowEqualSelector( ...@@ -156,11 +156,11 @@ const searchUris = createShallowEqualSelector(
); );
export default storeModule({ export default storeModule({
init: init, initialState,
namespace: 'frames', namespace: 'frames',
update: update, reducers,
actions: { actionCreators: {
connectFrame, connectFrame,
destroyFrame, destroyFrame,
updateFrameAnnotationFetchStatus, updateFrameAnnotationFetchStatus,
......
...@@ -9,7 +9,7 @@ import session from './session'; ...@@ -9,7 +9,7 @@ import session from './session';
* @typedef {import('../../../types/api').Group} Group * @typedef {import('../../../types/api').Group} Group
*/ */
function init() { function initialState() {
return { return {
/** /**
* List of groups. * List of groups.
...@@ -25,7 +25,7 @@ function init() { ...@@ -25,7 +25,7 @@ function init() {
}; };
} }
const update = { const reducers = {
FOCUS_GROUP(state, action) { FOCUS_GROUP(state, action) {
const group = state.groups.find(g => g.id === action.id); const group = state.groups.find(g => g.id === action.id);
if (!group) { if (!group) {
...@@ -67,7 +67,7 @@ const update = { ...@@ -67,7 +67,7 @@ const update = {
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
function clearGroups() { function clearGroups() {
return { return {
...@@ -198,10 +198,10 @@ const getCurrentlyViewingGroups = createSelector( ...@@ -198,10 +198,10 @@ const getCurrentlyViewingGroups = createSelector(
); );
export default storeModule({ export default storeModule({
init, initialState,
namespace: 'groups', namespace: 'groups',
update, reducers,
actions: { actionCreators: {
focusGroup, focusGroup,
loadGroups, loadGroups,
clearGroups, clearGroups,
......
...@@ -2,11 +2,11 @@ import { actionTypes } from '../util'; ...@@ -2,11 +2,11 @@ import { actionTypes } from '../util';
import { replaceURLParams } from '../../util/url'; import { replaceURLParams } from '../../util/url';
import { storeModule } from '../create-store'; import { storeModule } from '../create-store';
function init() { function initialState() {
return null; return null;
} }
const update = { const reducers = {
UPDATE_LINKS(state, action) { UPDATE_LINKS(state, action) {
return { return {
...action.links, ...action.links,
...@@ -14,7 +14,7 @@ const update = { ...@@ -14,7 +14,7 @@ const update = {
}, },
}; };
const actions = actionTypes(update); const actions = actionTypes(reducers);
/** /**
* Update the link map * Update the link map
...@@ -54,10 +54,10 @@ function getLink(state, linkName, params = {}) { ...@@ -54,10 +54,10 @@ function getLink(state, linkName, params = {}) {
} }
export default storeModule({ export default storeModule({
init, initialState,
namespace: 'links', namespace: 'links',
update, reducers,
actions: { actionCreators: {
updateLinks, updateLinks,
}, },
selectors: { selectors: {
......
...@@ -16,7 +16,7 @@ import annotations from './annotations'; ...@@ -16,7 +16,7 @@ import annotations from './annotations';
import groups from './groups'; import groups from './groups';
import route from './route'; import route from './route';
function init() { function initialState() {
return { return {
// Map of ID -> updated annotation for updates that have been received over // Map of ID -> updated annotation for updates that have been received over
// the WebSocket but not yet applied // the WebSocket but not yet applied
...@@ -28,7 +28,7 @@ function init() { ...@@ -28,7 +28,7 @@ function init() {
}; };
} }
const update = { const reducers = {
RECEIVE_REAL_TIME_UPDATES(state, action) { RECEIVE_REAL_TIME_UPDATES(state, action) {
return { return {
pendingUpdates: { ...action.pendingUpdates }, pendingUpdates: { ...action.pendingUpdates },
...@@ -76,7 +76,7 @@ const update = { ...@@ -76,7 +76,7 @@ const update = {
}, },
}; };
const actions = actionTypes(update); const actions = actionTypes(reducers);
/** /**
* Record pending updates representing changes on the server that the client * Record pending updates representing changes on the server that the client
...@@ -184,10 +184,10 @@ function hasPendingDeletion(state, id) { ...@@ -184,10 +184,10 @@ function hasPendingDeletion(state, id) {
} }
export default storeModule({ export default storeModule({
init, initialState,
namespace: 'realTimeUpdates', namespace: 'realTimeUpdates',
update, reducers,
actions: { actionCreators: {
receiveRealTimeUpdates, receiveRealTimeUpdates,
clearPendingUpdates, clearPendingUpdates,
}, },
......
...@@ -2,7 +2,7 @@ import { actionTypes } from '../util'; ...@@ -2,7 +2,7 @@ import { actionTypes } from '../util';
import { storeModule } from '../create-store'; import { storeModule } from '../create-store';
function init() { function initialState() {
return { return {
/** /**
* The current route. * The current route.
...@@ -21,18 +21,18 @@ function init() { ...@@ -21,18 +21,18 @@ function init() {
}; };
} }
const update = { const reducers = {
CHANGE_ROUTE(state, { name, params }) { CHANGE_ROUTE(state, { name, params }) {
return { name, params }; return { name, params };
}, },
}; };
const actions = actionTypes(update); const actions = actionTypes(reducers);
/** /**
* Change the active route. * Change the active route.
* *
* @param {string} name - Name of the route to activate. See `init` for possible values * @param {string} name - Name of the route to activate. See `initialState` for possible values
* @param {Object.<string,string>} params - Parameters associated with the route * @param {Object.<string,string>} params - Parameters associated with the route
*/ */
function changeRoute(name, params = {}) { function changeRoute(name, params = {}) {
...@@ -59,10 +59,10 @@ function routeParams(state) { ...@@ -59,10 +59,10 @@ function routeParams(state) {
} }
export default storeModule({ export default storeModule({
init, initialState,
namespace: 'route', namespace: 'route',
update, reducers,
actions: { actionCreators: {
changeRoute, changeRoute,
}, },
selectors: { selectors: {
......
...@@ -44,7 +44,7 @@ function initialSelection(settings) { ...@@ -44,7 +44,7 @@ function initialSelection(settings) {
return selection; return selection;
} }
function init(settings) { function initialState(settings) {
return { return {
/** /**
* The following objects map annotation identifiers to a boolean * The following objects map annotation identifiers to a boolean
...@@ -100,7 +100,7 @@ const resetSelection = () => { ...@@ -100,7 +100,7 @@ const resetSelection = () => {
}; };
}; };
const update = { const reducers = {
CLEAR_SELECTION: function () { CLEAR_SELECTION: function () {
return resetSelection(); return resetSelection();
}, },
...@@ -204,7 +204,7 @@ const update = { ...@@ -204,7 +204,7 @@ const update = {
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
/* Action Creators */ /* Action Creators */
...@@ -388,11 +388,11 @@ const sortKeys = createSelector( ...@@ -388,11 +388,11 @@ const sortKeys = createSelector(
); );
export default storeModule({ export default storeModule({
init: init, initialState,
namespace: 'selection', namespace: 'selection',
update: update, reducers,
actions: { actionCreators: {
clearSelection, clearSelection,
selectAnnotations, selectAnnotations,
selectTab, selectTab,
......
...@@ -23,7 +23,7 @@ const initialProfile = { ...@@ -23,7 +23,7 @@ const initialProfile = {
userid: null, userid: null,
}; };
function init(settings) { function initialState(settings) {
return { return {
/** /**
* The app's default authority (user identity provider), from settings, * The app's default authority (user identity provider), from settings,
...@@ -41,7 +41,7 @@ function init(settings) { ...@@ -41,7 +41,7 @@ function init(settings) {
}; };
} }
const update = { const reducers = {
UPDATE_PROFILE: function (state, action) { UPDATE_PROFILE: function (state, action) {
return { return {
profile: { ...action.profile }, profile: { ...action.profile },
...@@ -49,7 +49,7 @@ const update = { ...@@ -49,7 +49,7 @@ const update = {
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
/** /**
* Update the profile information for the current user. * Update the profile information for the current user.
...@@ -111,11 +111,11 @@ function profile(state) { ...@@ -111,11 +111,11 @@ function profile(state) {
} }
export default storeModule({ export default storeModule({
init, initialState,
namespace: 'session', namespace: 'session',
update, reducers,
actions: { actionCreators: {
updateProfile, updateProfile,
}, },
......
...@@ -16,7 +16,7 @@ import * as util from '../util'; ...@@ -16,7 +16,7 @@ import * as util from '../util';
import { storeModule } from '../create-store'; import { storeModule } from '../create-store';
function init() { function initialState() {
return { return {
/* /*
* The `panelName` of the currently-active sidebar panel. * The `panelName` of the currently-active sidebar panel.
...@@ -32,7 +32,7 @@ function init() { ...@@ -32,7 +32,7 @@ function init() {
}; };
} }
const update = { const reducers = {
OPEN_SIDEBAR_PANEL: function (state, action) { OPEN_SIDEBAR_PANEL: function (state, action) {
return { activePanelName: action.panelName }; return { activePanelName: action.panelName };
}, },
...@@ -76,7 +76,7 @@ const update = { ...@@ -76,7 +76,7 @@ const update = {
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
/** /**
* Designate `panelName` as the currently-active panel name * Designate `panelName` as the currently-active panel name
...@@ -124,10 +124,10 @@ function isSidebarPanelOpen(state, panelName) { ...@@ -124,10 +124,10 @@ function isSidebarPanelOpen(state, panelName) {
export default storeModule({ export default storeModule({
namespace: 'sidebarPanels', namespace: 'sidebarPanels',
init: init, initialState,
update: update, reducers,
actions: { actionCreators: {
openSidebarPanel, openSidebarPanel,
closeSidebarPanel, closeSidebarPanel,
toggleSidebarPanel, toggleSidebarPanel,
......
...@@ -5,8 +5,8 @@ import realTimeUpdates from '../real-time-updates'; ...@@ -5,8 +5,8 @@ import realTimeUpdates from '../real-time-updates';
import { $imports } from '../real-time-updates'; import { $imports } from '../real-time-updates';
import selection from '../selection'; import selection from '../selection';
const { removeAnnotations } = annotations.actions; const { removeAnnotations } = annotations.actionCreators;
const { focusGroup } = groups.actions; const { focusGroup } = groups.actionCreators;
describe('sidebar/store/modules/real-time-updates', () => { describe('sidebar/store/modules/real-time-updates', () => {
let fakeAnnotationExists; let fakeAnnotationExists;
......
...@@ -12,7 +12,7 @@ describe('sidebar/store/modules/sidebar-panels', () => { ...@@ -12,7 +12,7 @@ describe('sidebar/store/modules/sidebar-panels', () => {
store = createStore([sidebarPanels]); store = createStore([sidebarPanels]);
}); });
describe('#init', () => { describe('#initialState', () => {
it('sets initial `activePanelName` to `null`', () => { it('sets initial `activePanelName` to `null`', () => {
assert.equal(getSidebarPanelsState().activePanelName, null); assert.equal(getSidebarPanelsState().activePanelName, null);
}); });
......
...@@ -16,13 +16,13 @@ import * as util from '../util'; ...@@ -16,13 +16,13 @@ import * as util from '../util';
* maintains state only; it's up to other layers to handle the management * maintains state only; it's up to other layers to handle the management
* and interactions with these messages. * and interactions with these messages.
*/ */
function init() { function initialState() {
return { return {
messages: [], messages: [],
}; };
} }
const update = { const reducers = {
ADD_MESSAGE: function (state, action) { ADD_MESSAGE: function (state, action) {
return { return {
messages: state.messages.concat({ ...action.message }), messages: state.messages.concat({ ...action.message }),
...@@ -47,7 +47,7 @@ const update = { ...@@ -47,7 +47,7 @@ const update = {
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
/** Actions */ /** Actions */
...@@ -113,10 +113,10 @@ function hasMessage(state, type, text) { ...@@ -113,10 +113,10 @@ function hasMessage(state, type, text) {
} }
export default storeModule({ export default storeModule({
init, initialState,
namespace: 'toastMessages', namespace: 'toastMessages',
update, reducers,
actions: { actionCreators: {
addToastMessage: addMessage, addToastMessage: addMessage,
removeToastMessage: removeMessage, removeToastMessage: removeMessage,
updateToastMessage: updateMessage, updateToastMessage: updateMessage,
......
...@@ -7,7 +7,7 @@ import { storeModule } from '../create-store'; ...@@ -7,7 +7,7 @@ import { storeModule } from '../create-store';
* sidebar. * sidebar.
*/ */
function init() { function initialState() {
return { return {
// Has the sidebar ever been opened? NB: This is not necessarily the // Has the sidebar ever been opened? NB: This is not necessarily the
// current state of the sidebar, but tracks whether it has ever been open // current state of the sidebar, but tracks whether it has ever been open
...@@ -16,7 +16,7 @@ function init() { ...@@ -16,7 +16,7 @@ function init() {
}; };
} }
const update = { const reducers = {
SET_HIGHLIGHTS_VISIBLE: function (state, action) { SET_HIGHLIGHTS_VISIBLE: function (state, action) {
return { visibleHighlights: action.visible }; return { visibleHighlights: action.visible };
}, },
...@@ -30,7 +30,7 @@ const update = { ...@@ -30,7 +30,7 @@ const update = {
}, },
}; };
const actions = util.actionTypes(update); const actions = util.actionTypes(reducers);
// Action creators // Action creators
...@@ -56,10 +56,10 @@ function hasSidebarOpened(state) { ...@@ -56,10 +56,10 @@ function hasSidebarOpened(state) {
} }
export default storeModule({ export default storeModule({
init: init, initialState,
namespace: 'viewer', namespace: 'viewer',
update: update, reducers,
actions: { actionCreators: {
setShowHighlights, setShowHighlights,
setSidebarOpened, setSidebarOpened,
}, },
......
...@@ -7,12 +7,12 @@ const A = 0; ...@@ -7,12 +7,12 @@ const A = 0;
const modules = [ const modules = [
{ {
// namespaced module A // namespaced module A
init(value = 0) { initialState(value = 0) {
return { count: value }; return { count: value };
}, },
namespace: 'a', namespace: 'a',
update: { reducers: {
INCREMENT_COUNTER_A: (state, action) => { INCREMENT_COUNTER_A: (state, action) => {
return { count: state.count + action.amount }; return { count: state.count + action.amount };
}, },
...@@ -21,7 +21,7 @@ const modules = [ ...@@ -21,7 +21,7 @@ const modules = [
}, },
}, },
actions: { actionCreators: {
incrementA(amount) { incrementA(amount) {
return { type: 'INCREMENT_COUNTER_A', amount }; return { type: 'INCREMENT_COUNTER_A', amount };
}, },
...@@ -41,12 +41,12 @@ const modules = [ ...@@ -41,12 +41,12 @@ const modules = [
}, },
{ {
// namespaced module B // namespaced module B
init(value = 0) { initialState(value = 0) {
return { count: value }; return { count: value };
}, },
namespace: 'b', namespace: 'b',
update: { reducers: {
INCREMENT_COUNTER_B: (state, action) => { INCREMENT_COUNTER_B: (state, action) => {
return { count: state.count + action.amount }; return { count: state.count + action.amount };
}, },
...@@ -55,7 +55,7 @@ const modules = [ ...@@ -55,7 +55,7 @@ const modules = [
}, },
}, },
actions: { actionCreators: {
incrementB(amount) { incrementB(amount) {
return { type: 'INCREMENT_COUNTER_B', amount }; return { type: 'INCREMENT_COUNTER_B', amount };
}, },
...@@ -95,7 +95,7 @@ describe('createStore', () => { ...@@ -95,7 +95,7 @@ describe('createStore', () => {
assert.calledWith(subscriber); assert.calledWith(subscriber);
}); });
it('passes initial state args to `init` function', () => { it('passes initial state args to `initialState` function', () => {
const store = counterStore([21]); const store = counterStore([21]);
assert.equal(store.getState().a.count, 21); assert.equal(store.getState().a.count, 21);
}); });
...@@ -108,20 +108,20 @@ describe('createStore', () => { ...@@ -108,20 +108,20 @@ describe('createStore', () => {
it('adds selectors as methods to the store', () => { it('adds selectors as methods to the store', () => {
const store = counterStore(); const store = counterStore();
store.dispatch(modules[A].actions.incrementA(5)); store.dispatch(modules[A].actionCreators.incrementA(5));
assert.equal(store.getCountA(), 5); assert.equal(store.getCountA(), 5);
}); });
it('adds root selectors as methods to the store', () => { it('adds root selectors as methods to the store', () => {
const store = counterStore(); const store = counterStore();
store.dispatch(modules[A].actions.incrementA(5)); store.dispatch(modules[A].actionCreators.incrementA(5));
assert.equal(store.getCountAFromRoot(), 5); assert.equal(store.getCountAFromRoot(), 5);
}); });
it('applies `thunk` middleware by default', () => { it('applies `thunk` middleware by default', () => {
const store = counterStore(); const store = counterStore();
const doubleAction = (dispatch, getState) => { const doubleAction = (dispatch, getState) => {
dispatch(modules[A].actions.incrementA(getState().a.count)); dispatch(modules[A].actionCreators.incrementA(getState().a.count));
}; };
store.incrementA(5); store.incrementA(5);
......
...@@ -8,11 +8,11 @@ import { useStoreProxy, $imports } from '../use-store'; ...@@ -8,11 +8,11 @@ import { useStoreProxy, $imports } from '../use-store';
const thingsModule = { const thingsModule = {
namespace: 'things', namespace: 'things',
init: () => ({ initialState: () => ({
things: [], things: [],
}), }),
update: { reducers: {
ADD_THING(state, action) { ADD_THING(state, action) {
if (state.things.some(t => t.id === action.thing.id)) { if (state.things.some(t => t.id === action.thing.id)) {
return {}; return {};
...@@ -21,7 +21,7 @@ const thingsModule = { ...@@ -21,7 +21,7 @@ const thingsModule = {
}, },
}, },
actions: { actionCreators: {
addThing(id) { addThing(id) {
return { type: 'ADD_THING', thing: { id } }; return { type: 'ADD_THING', thing: { id } };
}, },
......
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