Use Redux Action type

This commit is contained in:
Josh Johnson 2019-11-03 17:00:00 +00:00
parent 113941ba0d
commit 239f0607db
4 changed files with 18 additions and 11 deletions

View file

@ -1,4 +1,5 @@
/**
* @typedef {import('redux').Action} Action
* @typedef {import('../../../types/index').Choices.Choice} Choice
*/
@ -6,7 +7,7 @@ import { ACTION_TYPES } from '../constants';
/**
* @argument {Choice} choice
* @returns {{ type: string } & Choice}
* @returns {Action & Choice}
*/
export const addChoice = ({
value,
@ -33,7 +34,7 @@ export const addChoice = ({
/**
* @argument {Choice[]} results
* @returns {{ type: string, results: Choice[] }}
* @returns {Action & { results: Choice[] }}
*/
export const filterChoices = results => ({
type: ACTION_TYPES.FILTER_CHOICES,
@ -42,7 +43,7 @@ export const filterChoices = results => ({
/**
* @argument {boolean} active
* @returns {{ type: string, active: boolean }}
* @returns {Action & { active: boolean }}
*/
export const activateChoices = (active = true) => ({
type: ACTION_TYPES.ACTIVATE_CHOICES,
@ -50,7 +51,7 @@ export const activateChoices = (active = true) => ({
});
/**
* @returns {{ type: string }}
* @returns {Action}
*/
export const clearChoices = () => ({
type: ACTION_TYPES.CLEAR_CHOICES,

View file

@ -1,12 +1,13 @@
import { ACTION_TYPES } from '../constants';
/**
* @typedef {import('redux').Action} Action
* @typedef {import('../../../types/index').Choices.Group} Group
*/
/**
* @param {Group} group
* @returns {{ type: string } & Group}
* @returns {Action & Group}
*/
export const addGroup = ({ value, id, active, disabled }) => ({
type: ACTION_TYPES.ADD_GROUP,

View file

@ -1,12 +1,13 @@
import { ACTION_TYPES } from '../constants';
/**
* @typedef {import('redux').Action} Action
* @typedef {import('../../../types/index').Choices.Item} Item
*/
/**
* @param {Item} item
* @returns {{ type: string } & Item}
* @returns {Action & Item}
*/
export const addItem = ({
value,
@ -32,7 +33,7 @@ export const addItem = ({
/**
* @param {string} id
* @param {string} choiceId
* @returns {{ type: string, id: string, choiceId: string }}
* @returns {Action & { id: string, choiceId: string }}
*/
export const removeItem = (id, choiceId) => ({
type: ACTION_TYPES.REMOVE_ITEM,
@ -43,7 +44,7 @@ export const removeItem = (id, choiceId) => ({
/**
* @param {string} id
* @param {boolean} highlighted
* @returns {{ type: string, id: string, highlighted: boolean }}
* @returns {Action & { id: string, highlighted: boolean }}
*/
export const highlightItem = (id, highlighted) => ({
type: ACTION_TYPES.HIGHLIGHT_ITEM,

View file

@ -1,5 +1,9 @@
/**
* @returns {{ type: string }}
* @typedef {import('redux').Action} Action
*/
/**
* @returns {Action}
*/
export const clearAll = () => ({
type: 'CLEAR_ALL',
@ -7,7 +11,7 @@ export const clearAll = () => ({
/**
* @param {any} state
* @returns {{ type: string, state: object }}
* @returns {Action & { state: object }}
*/
export const resetTo = state => ({
type: 'RESET_TO',
@ -16,7 +20,7 @@ export const resetTo = state => ({
/**
* @param {boolean} isLoading
* @returns {{ type: string, isLoading: boolean }}
* @returns {Action & { isLoading: boolean }}
*/
export const setIsLoading = isLoading => ({
type: 'SET_IS_LOADING',