mirror of
https://github.com/codex-team/editor.js
synced 2024-06-08 00:42:31 +02:00
e6db8d5140
* 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>
30 lines
667 B
TypeScript
30 lines
667 B
TypeScript
import { Action } from './action';
|
|
import { EditorState } from './editorState';
|
|
import { Listener } from './listener';
|
|
|
|
/**
|
|
* Store type contains functions for use it
|
|
*/
|
|
export interface Store {
|
|
/**
|
|
* Function for subscribing on state changes
|
|
*
|
|
* @param listener - function, that will execute every state change
|
|
*
|
|
* @returns {() => void} unsubscribe function
|
|
*/
|
|
subscribe: (listener: Listener) => (() => void);
|
|
|
|
/**
|
|
* Dispatch action on the current state
|
|
*
|
|
* @param action - action that will be dispatched
|
|
*/
|
|
dispatch: (action: Action) => void;
|
|
|
|
/**
|
|
* Function returns current state
|
|
*/
|
|
getState: () => EditorState;
|
|
}
|