Commit 9ee2948c authored by Robert Knight's avatar Robert Knight

Add types for frames store module

parent 9f360335
...@@ -5,8 +5,7 @@ import { ...@@ -5,8 +5,7 @@ import {
} from 'reselect'; } from 'reselect';
import shallowEqual from 'shallowequal'; import shallowEqual from 'shallowequal';
import * as util from '../util'; import { createStoreModule, makeAction } from '../create-store';
import { createStoreModule } from '../create-store';
/** /**
* @typedef {import('../../../types/annotator').DocumentMetadata} DocumentMetadata * @typedef {import('../../../types/annotator').DocumentMetadata} DocumentMetadata
...@@ -27,15 +26,27 @@ const initialState = []; ...@@ -27,15 +26,27 @@ const initialState = [];
/** @typedef {typeof initialState} State */ /** @typedef {typeof initialState} State */
const reducers = { const reducers = {
CONNECT_FRAME: function (state, action) { /**
* @param {State} state
* @param {{ frame: Frame }} action
*/
CONNECT_FRAME(state, action) {
return [...state, action.frame]; return [...state, action.frame];
}, },
DESTROY_FRAME: function (state, action) { /**
* @param {State} state
* @param {{ frame: Frame }} action
*/
DESTROY_FRAME(state, action) {
return state.filter(f => f !== action.frame); return state.filter(f => f !== action.frame);
}, },
UPDATE_FRAME_ANNOTATION_FETCH_STATUS: function (state, action) { /**
* @param {State} state
* @param {{ uri: string, isAnnotationFetchComplete: boolean }} action
*/
UPDATE_FRAME_ANNOTATION_FETCH_STATUS(state, action) {
const frames = state.map(frame => { const frames = state.map(frame => {
const match = frame.uri && frame.uri === action.uri; const match = frame.uri && frame.uri === action.uri;
if (match) { if (match) {
...@@ -50,15 +61,13 @@ const reducers = { ...@@ -50,15 +61,13 @@ const reducers = {
}, },
}; };
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.
* *
* @param {Frame} frame * @param {Frame} frame
*/ */
function connectFrame(frame) { function connectFrame(frame) {
return { type: actions.CONNECT_FRAME, frame }; return makeAction(reducers, 'CONNECT_FRAME', { frame });
} }
/** /**
...@@ -67,7 +76,7 @@ function connectFrame(frame) { ...@@ -67,7 +76,7 @@ function connectFrame(frame) {
* @param {Frame} frame * @param {Frame} frame
*/ */
function destroyFrame(frame) { function destroyFrame(frame) {
return { type: actions.DESTROY_FRAME, frame }; return makeAction(reducers, 'DESTROY_FRAME', { frame });
} }
/** /**
...@@ -77,17 +86,16 @@ function destroyFrame(frame) { ...@@ -77,17 +86,16 @@ function destroyFrame(frame) {
* @param {boolean} isFetchComplete * @param {boolean} isFetchComplete
*/ */
function updateFrameAnnotationFetchStatus(uri, isFetchComplete) { function updateFrameAnnotationFetchStatus(uri, isFetchComplete) {
return { return makeAction(reducers, 'UPDATE_FRAME_ANNOTATION_FETCH_STATUS', {
type: actions.UPDATE_FRAME_ANNOTATION_FETCH_STATUS,
isAnnotationFetchComplete: isFetchComplete,
uri, uri,
}; isAnnotationFetchComplete: isFetchComplete,
});
} }
/** /**
* Return the list of frames currently connected to the sidebar app. * Return the list of frames currently connected to the sidebar app.
* *
* @return {Frame[]} * @param {State} state
*/ */
function frames(state) { function frames(state) {
return state; return state;
......
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