Commit 6cba2e65 authored by Robert Knight's avatar Robert Knight

Add types for "directLinked" store module

parent 65d131cd
import * as util from '../util'; import { createStoreModule, makeAction } from '../create-store';
import { createStoreModule } from '../create-store';
/** @param {import('../../../types/config').SidebarSettings} settings */
function initialState(settings) { function initialState(settings) {
return { return {
/** /**
...@@ -42,29 +41,47 @@ function initialState(settings) { ...@@ -42,29 +41,47 @@ function initialState(settings) {
}; };
} }
/** @typedef {ReturnType<initialState>} State */
const reducers = { const reducers = {
/**
* @param {State} state
* @param {{ directLinkedGroupFetchFailed: boolean }} action
*/
UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED(state, action) { UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED(state, action) {
return { return {
directLinkedGroupFetchFailed: action.directLinkedGroupFetchFailed, directLinkedGroupFetchFailed: action.directLinkedGroupFetchFailed,
}; };
}, },
/**
* @param {State} state
* @param {{ directLinkedGroupId: string }} action
*/
UPDATE_DIRECT_LINKED_GROUP_ID(state, action) { UPDATE_DIRECT_LINKED_GROUP_ID(state, action) {
return { return {
directLinkedGroupId: action.directLinkedGroupId, directLinkedGroupId: action.directLinkedGroupId,
}; };
}, },
/**
* @param {State} state
* @param {{ directLinkedAnnotationId: string }} action
*/
UPDATE_DIRECT_LINKED_ANNOTATION_ID(state, action) { UPDATE_DIRECT_LINKED_ANNOTATION_ID(state, action) {
return { return {
directLinkedAnnotationId: action.directLinkedAnnotationId, directLinkedAnnotationId: action.directLinkedAnnotationId,
}; };
}, },
CLEAR_DIRECT_LINKED_IDS() { CLEAR_DIRECT_LINKED_IDS() {
return { return {
directLinkedAnnotationId: null, directLinkedAnnotationId: null,
directLinkedGroupId: null, directLinkedGroupId: null,
}; };
}, },
CLEAR_SELECTION: function () {
CLEAR_SELECTION() {
return { return {
directLinkedAnnotationId: null, directLinkedAnnotationId: null,
directLinkedGroupId: null, directLinkedGroupId: null,
...@@ -73,46 +90,40 @@ const reducers = { ...@@ -73,46 +90,40 @@ const reducers = {
}, },
}; };
const actions = util.actionTypes(reducers);
/** /**
* Set the direct linked group id. * Set the direct linked group id.
*/ */
function setDirectLinkedGroupId(groupId) { function setDirectLinkedGroupId(groupId) {
return { return makeAction(reducers, 'UPDATE_DIRECT_LINKED_GROUP_ID', {
type: actions.UPDATE_DIRECT_LINKED_GROUP_ID,
directLinkedGroupId: groupId, directLinkedGroupId: groupId,
}; });
} }
/** /**
* Set the direct linked annotation's id. * Set the direct linked annotation's id.
*/ */
function setDirectLinkedAnnotationId(annId) { function setDirectLinkedAnnotationId(annId) {
return { return makeAction(reducers, 'UPDATE_DIRECT_LINKED_ANNOTATION_ID', {
type: actions.UPDATE_DIRECT_LINKED_ANNOTATION_ID,
directLinkedAnnotationId: annId, directLinkedAnnotationId: annId,
}; });
} }
/** /**
* Set the direct linked group fetch failure to true. * Set the direct linked group fetch failure to true.
*/ */
function setDirectLinkedGroupFetchFailed() { function setDirectLinkedGroupFetchFailed() {
return { return makeAction(reducers, 'UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED', {
type: actions.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,
directLinkedGroupFetchFailed: true, directLinkedGroupFetchFailed: true,
}; });
} }
/** /**
* Clear the direct linked group fetch failure. * Clear the direct linked group fetch failure.
*/ */
function clearDirectLinkedGroupFetchFailed() { function clearDirectLinkedGroupFetchFailed() {
return { return makeAction(reducers, 'UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED', {
type: actions.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,
directLinkedGroupFetchFailed: false, directLinkedGroupFetchFailed: false,
}; });
} }
/** /**
...@@ -122,22 +133,20 @@ function clearDirectLinkedGroupFetchFailed() { ...@@ -122,22 +133,20 @@ function clearDirectLinkedGroupFetchFailed() {
* not affect future group/annotation etc. fetches. * not affect future group/annotation etc. fetches.
*/ */
function clearDirectLinkedIds() { function clearDirectLinkedIds() {
return { return makeAction(reducers, 'CLEAR_DIRECT_LINKED_IDS', undefined);
type: actions.CLEAR_DIRECT_LINKED_IDS,
};
} }
/** /** @param {State} state */
* Selectors
*/
function directLinkedAnnotationId(state) { function directLinkedAnnotationId(state) {
return state.directLinkedAnnotationId; return state.directLinkedAnnotationId;
} }
/** @param {State} state */
function directLinkedGroupId(state) { function directLinkedGroupId(state) {
return state.directLinkedGroupId; return state.directLinkedGroupId;
} }
/** @param {State} state */
function directLinkedGroupFetchFailed(state) { function directLinkedGroupFetchFailed(state) {
return state.directLinkedGroupFetchFailed; return state.directLinkedGroupFetchFailed;
} }
......
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