editor.js/types/store/action.ts
Ilya Moroz e6db8d5140
[Feature] Add state manager (#2018)
* add state manager with demo file

* remove initial state

* move Store type to Store.ts

* add new actions

* change store schema

* add docs

* type -> interface, add deepCopy function

* move types to the /types/ folder

* rename types files, change state type (add blocks: key)

* fix createStore.ts func

* add documentation for reducer

* use BlockMutationType instead of ActionType

* add doc

* deep copy of initial state

* add doc for createStore

* Apply suggestions from code review

Co-authored-by: Peter Savchenko <specc.dev@gmail.com>

* rename `reducer` to `blocksReducer`

* add a listener type, pass changed state to the listener

Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
2022-05-05 14:26:04 +03:00

35 lines
848 B
TypeScript

import { OutputBlockData } from '../index';
import { BlockMutationType } from '../events/block/mutation-type';
/**
* Action for creating a new block in the editor
* This action will add the new block to the state
*/
interface CreateBlockAction {
type: BlockMutationType.Added;
data: OutputBlockData;
}
/**
* Action for changing data of an existing block
* This action will change block data in the state by its id
*/
interface ChangeBlockDataAction {
type: BlockMutationType.Changed;
data: OutputBlockData;
}
/**
* Action for removing a block from the editor
* This action will remove the block from the state by its id
*/
interface RemoveBlockAction {
type: BlockMutationType.Removed;
blockId: string;
}
/**
* Available action types
*/
export type Action = CreateBlockAction | ChangeBlockDataAction | RemoveBlockAction;