use named functions, rename action creators

This commit is contained in:
ilyamore88 2022-05-11 23:11:43 +03:00
parent 362a57e6cb
commit 5cf3100b5f
No known key found for this signature in database
GPG key ID: 3C27F3A104EBCE48
2 changed files with 22 additions and 16 deletions

View file

@ -7,27 +7,33 @@ import { ChangeBlockDataAction, CreateBlockAction, RemoveBlockAction } from '../
*
* @param block - new block data
*/
export const createBlock = (block: OutputBlockData): CreateBlockAction => ({
type: BlockMutationType.Added,
data: block,
});
export function makeCreateBlockAction(block: OutputBlockData): CreateBlockAction {
return {
type: BlockMutationType.Added,
data: block,
};
}
/**
* Action creator for changing block data in the store
*
* @param block - new block data
*/
export const changeBlock = (block: OutputBlockData): ChangeBlockDataAction => ({
type: BlockMutationType.Changed,
data: block,
});
export function makeChangeBlockAction(block: OutputBlockData): ChangeBlockDataAction {
return {
type: BlockMutationType.Changed,
data: block,
};
}
/**
* Action creator for removing block data from the store
*
* @param blockId - id of a block for removing
*/
export const removeBlock = (blockId: string): RemoveBlockAction => ({
type: BlockMutationType.Removed,
blockId,
});
export function makeRemoveBlockAction(blockId: string): RemoveBlockAction {
return {
type: BlockMutationType.Removed,
blockId,
};
}

View file

@ -1,7 +1,7 @@
import createStore from '../../../../src/components/store/createStore';
import { EditorState } from '../../../../types/store/editorState';
import blocksReducer from '../../../../src/components/store/blocksReducer';
import { changeBlock, createBlock, removeBlock } from '../../../../src/components/store/actions/blockReducerActions';
import { makeChangeBlockAction, makeCreateBlockAction, makeRemoveBlockAction } from '../../../../src/components/store/actions/blockReducerActions';
describe('State manager', () => {
it('should create the store without initial state', () => {
@ -49,7 +49,7 @@ describe('State manager', () => {
},
};
store.dispatch(createBlock(block));
store.dispatch(makeCreateBlockAction(block));
expect(store.getState()).to.be.deep.equal(expectedResult);
});
@ -81,7 +81,7 @@ describe('State manager', () => {
},
};
store.dispatch(changeBlock(changedBlock));
store.dispatch(makeChangeBlockAction(changedBlock));
expect(store.getState()).to.be.deep.equal(expectedResult);
});
@ -104,7 +104,7 @@ describe('State manager', () => {
blocks: {},
};
store.dispatch(removeBlock(block.id));
store.dispatch(makeRemoveBlockAction(block.id));
expect(store.getState()).to.be.deep.equal(expectedResult);
});