Commit 1125ec3a authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate defaults store module to TypeScript

parent dda46a72
...@@ -14,31 +14,25 @@ import { createStoreModule, makeAction } from '../create-store'; ...@@ -14,31 +14,25 @@ import { createStoreModule, makeAction } from '../create-store';
* `persistedDefaults` service. * `persistedDefaults` service.
*/ */
const initialState = { export type State = {
annotationPrivacy: /** @type {'private'|'shared'|null} */ (null), annotationPrivacy: 'private' | 'shared' | null;
focusedGroup: /** @type {string|null} */ (null), focusedGroup: string | null;
}; };
/** export type Key = keyof State;
* @typedef {keyof initialState} Key
* @typedef {typeof initialState} State const initialState: State = {
*/ annotationPrivacy: null,
focusedGroup: null,
};
const reducers = { const reducers = {
/** SET_DEFAULT(state: State, action: { defaultKey: Key; value: string | null }) {
* @param {State} state
* @param {{ defaultKey: Key, value: string|null }} action
*/
SET_DEFAULT(state, action) {
return { [action.defaultKey]: action.value }; return { [action.defaultKey]: action.value };
}, },
}; };
/** function setDefault(defaultKey: Key, value: string | null) {
* @param {Key} defaultKey
* @param {string|null} value
*/
function setDefault(defaultKey, value) {
return makeAction(reducers, 'SET_DEFAULT', { defaultKey, value }); return makeAction(reducers, 'SET_DEFAULT', { defaultKey, value });
} }
...@@ -46,16 +40,12 @@ function setDefault(defaultKey, value) { ...@@ -46,16 +40,12 @@ function setDefault(defaultKey, value) {
/** /**
* Retrieve the state's current value for `defaultKey`. * Retrieve the state's current value for `defaultKey`.
*
* @param {State} state
* @param {Key} defaultKey
*/ */
function getDefault(state, defaultKey) { function getDefault(state: State, defaultKey: Key) {
return state[defaultKey]; return state[defaultKey];
} }
/** @param {State} state */ function getDefaults(state: State) {
function getDefaults(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