mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-27 09:50:10 +02:00
Add types to actions
This commit is contained in:
parent
3f850f61d6
commit
f7cad9db9d
|
@ -1,14 +1,7 @@
|
|||
/**
|
||||
* @typedef {import('redux').Action} Action
|
||||
* @typedef {import('../../../types/index').Choices.Choice} Choice
|
||||
*/
|
||||
|
||||
import { Action } from 'redux';
|
||||
import { ACTION_TYPES } from '../constants';
|
||||
import { Choice } from '../interfaces';
|
||||
|
||||
/**
|
||||
* @argument {Choice} choice
|
||||
* @returns {Action & Choice}
|
||||
*/
|
||||
export const addChoice = ({
|
||||
value,
|
||||
label,
|
||||
|
@ -19,7 +12,7 @@ export const addChoice = ({
|
|||
customProperties,
|
||||
placeholder,
|
||||
keyCode,
|
||||
}) => ({
|
||||
}): Action & Choice => ({
|
||||
type: ACTION_TYPES.ADD_CHOICE,
|
||||
value,
|
||||
label,
|
||||
|
@ -32,27 +25,20 @@ export const addChoice = ({
|
|||
keyCode,
|
||||
});
|
||||
|
||||
/**
|
||||
* @argument {Choice[]} results
|
||||
* @returns {Action & { results: Choice[] }}
|
||||
*/
|
||||
export const filterChoices = results => ({
|
||||
export const filterChoices = (
|
||||
results: Choice[],
|
||||
): Action & { results: Choice[] } => ({
|
||||
type: ACTION_TYPES.FILTER_CHOICES,
|
||||
results,
|
||||
});
|
||||
|
||||
/**
|
||||
* @argument {boolean} active
|
||||
* @returns {Action & { active: boolean }}
|
||||
*/
|
||||
export const activateChoices = (active = true) => ({
|
||||
export const activateChoices = (
|
||||
active = true,
|
||||
): Action & { active: boolean } => ({
|
||||
type: ACTION_TYPES.ACTIVATE_CHOICES,
|
||||
active,
|
||||
});
|
||||
|
||||
/**
|
||||
* @returns {Action}
|
||||
*/
|
||||
export const clearChoices = () => ({
|
||||
export const clearChoices = (): Action => ({
|
||||
type: ACTION_TYPES.CLEAR_CHOICES,
|
||||
});
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
import { Action } from 'redux';
|
||||
import { ACTION_TYPES } from '../constants';
|
||||
import { Group } from '../interfaces';
|
||||
|
||||
/**
|
||||
* @typedef {import('redux').Action} Action
|
||||
* @typedef {import('../../../types/index').Choices.Group} Group
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Group} group
|
||||
* @returns {Action & Group}
|
||||
*/
|
||||
export const addGroup = ({ value, id, active, disabled }) => ({
|
||||
export const addGroup = ({
|
||||
value,
|
||||
id,
|
||||
active,
|
||||
disabled,
|
||||
}: Group): Action & Group => ({
|
||||
type: ACTION_TYPES.ADD_GROUP,
|
||||
value,
|
||||
id,
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
import { Action } from 'redux';
|
||||
import { ACTION_TYPES } from '../constants';
|
||||
import { Item } from '../interfaces';
|
||||
|
||||
/**
|
||||
* @typedef {import('redux').Action} Action
|
||||
* @typedef {import('../../../types/index').Choices.Item} Item
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Item} item
|
||||
* @returns {Action & Item}
|
||||
*/
|
||||
export const addItem = ({
|
||||
value,
|
||||
label,
|
||||
|
@ -18,7 +11,7 @@ export const addItem = ({
|
|||
customProperties,
|
||||
placeholder,
|
||||
keyCode,
|
||||
}) => ({
|
||||
}: Item): Action & Item => ({
|
||||
type: ACTION_TYPES.ADD_ITEM,
|
||||
value,
|
||||
label,
|
||||
|
@ -30,23 +23,19 @@ export const addItem = ({
|
|||
keyCode,
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {number} id
|
||||
* @param {number} choiceId
|
||||
* @returns {Action & { id: number, choiceId: number }}
|
||||
*/
|
||||
export const removeItem = (id, choiceId) => ({
|
||||
export const removeItem = (
|
||||
id: number,
|
||||
choiceId: number,
|
||||
): Action & { id: number; choiceId: number } => ({
|
||||
type: ACTION_TYPES.REMOVE_ITEM,
|
||||
id,
|
||||
choiceId,
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {number} id
|
||||
* @param {boolean} highlighted
|
||||
* @returns {Action & { id: number, highlighted: boolean }}
|
||||
*/
|
||||
export const highlightItem = (id, highlighted) => ({
|
||||
export const highlightItem = (
|
||||
id: number,
|
||||
highlighted: boolean,
|
||||
): Action & { id: number; highlighted: boolean } => ({
|
||||
type: ACTION_TYPES.HIGHLIGHT_ITEM,
|
||||
id,
|
||||
highlighted,
|
||||
|
|
|
@ -1,28 +1,18 @@
|
|||
/**
|
||||
* @typedef {import('redux').Action} Action
|
||||
*/
|
||||
import { Action } from 'redux';
|
||||
import { State } from '../interfaces';
|
||||
|
||||
/**
|
||||
* @returns {Action}
|
||||
*/
|
||||
export const clearAll = () => ({
|
||||
export const clearAll = (): Action => ({
|
||||
type: 'CLEAR_ALL',
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {any} state
|
||||
* @returns {Action & { state: object }}
|
||||
*/
|
||||
export const resetTo = state => ({
|
||||
export const resetTo = (state: State): Action & { state: State } => ({
|
||||
type: 'RESET_TO',
|
||||
state,
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {boolean} isLoading
|
||||
* @returns {Action & { isLoading: boolean }}
|
||||
*/
|
||||
export const setIsLoading = isLoading => ({
|
||||
export const setIsLoading = (
|
||||
isLoading: boolean,
|
||||
): Action & { isLoading: boolean } => ({
|
||||
type: 'SET_IS_LOADING',
|
||||
isLoading,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue