mirror of
https://github.com/codex-team/editor.js
synced 2024-06-02 14:02:17 +02:00
40 lines
1,018 B
TypeScript
40 lines
1,018 B
TypeScript
import { OutputBlockData } from '../../../../types';
|
|
import { BlockMutationType } from '../../../../types/events/block/mutation-type';
|
|
import { ChangeBlockDataAction, CreateBlockAction, RemoveBlockAction } from '../../../../types/store/action';
|
|
|
|
/**
|
|
* Action creator for creating a new block in the store
|
|
*
|
|
* @param block - new block data
|
|
*/
|
|
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 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 function makeRemoveBlockAction(blockId: string): RemoveBlockAction {
|
|
return {
|
|
type: BlockMutationType.Removed,
|
|
blockId,
|
|
};
|
|
}
|