mirror of
https://github.com/codex-team/editor.js
synced 2024-06-10 18:03:25 +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
|
* @param block - new block data
|
||||||
*/
|
*/
|
||||||
export const createBlock = (block: OutputBlockData): CreateBlockAction => ({
|
export function makeCreateBlockAction(block: OutputBlockData): CreateBlockAction {
|
||||||
type: BlockMutationType.Added,
|
return {
|
||||||
data: block,
|
type: BlockMutationType.Added,
|
||||||
});
|
data: block,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action creator for changing block data in the store
|
* Action creator for changing block data in the store
|
||||||
*
|
*
|
||||||
* @param block - new block data
|
* @param block - new block data
|
||||||
*/
|
*/
|
||||||
export const changeBlock = (block: OutputBlockData): ChangeBlockDataAction => ({
|
export function makeChangeBlockAction(block: OutputBlockData): ChangeBlockDataAction {
|
||||||
type: BlockMutationType.Changed,
|
return {
|
||||||
data: block,
|
type: BlockMutationType.Changed,
|
||||||
});
|
data: block,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action creator for removing block data from the store
|
* Action creator for removing block data from the store
|
||||||
*
|
*
|
||||||
* @param blockId - id of a block for removing
|
* @param blockId - id of a block for removing
|
||||||
*/
|
*/
|
||||||
export const removeBlock = (blockId: string): RemoveBlockAction => ({
|
export function makeRemoveBlockAction(blockId: string): RemoveBlockAction {
|
||||||
type: BlockMutationType.Removed,
|
return {
|
||||||
blockId,
|
type: BlockMutationType.Removed,
|
||||||
});
|
blockId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import createStore from '../../../../src/components/store/createStore';
|
import createStore from '../../../../src/components/store/createStore';
|
||||||
import { EditorState } from '../../../../types/store/editorState';
|
import { EditorState } from '../../../../types/store/editorState';
|
||||||
import blocksReducer from '../../../../src/components/store/blocksReducer';
|
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', () => {
|
describe('State manager', () => {
|
||||||
it('should create the store without initial state', () => {
|
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);
|
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);
|
expect(store.getState()).to.be.deep.equal(expectedResult);
|
||||||
});
|
});
|
||||||
|
@ -104,7 +104,7 @@ describe('State manager', () => {
|
||||||
blocks: {},
|
blocks: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
store.dispatch(removeBlock(block.id));
|
store.dispatch(makeRemoveBlockAction(block.id));
|
||||||
|
|
||||||
expect(store.getState()).to.be.deep.equal(expectedResult);
|
expect(store.getState()).to.be.deep.equal(expectedResult);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue