mirror of
https://github.com/codex-team/editor.js
synced 2024-05-19 06:47:16 +02:00
use named functions, rename action creators
This commit is contained in:
parent
362a57e6cb
commit
5cf3100b5f
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue