undo-redo-vuex
Version:
A Vuex plugin for module namespaced undo and redo functionality. This plugin takes inspiration from and extends the work of [vuex-undo-redo](https://github.com/anthonygore/vuex-undo-redo).
34 lines (28 loc) • 671 B
text/typescript
import { RESET_STATE } from "./constants";
import { getConfig, setConfig, updateCanUndoRedo } from "./utils-undo-redo";
export default ({
paths,
store
}: {
paths: UndoRedoOptions[];
store: any;
}) => async (namespace: string) => {
const config = getConfig(paths)(namespace);
if (Object.keys(config).length) {
const done: [] = [];
const undone: [] = [];
config.newMutation = false;
store.commit(`${namespace}${RESET_STATE}`);
config.newMutation = true;
setConfig(paths)(
namespace,
{
...config,
done,
undone
},
store
);
updateCanUndoRedo({ paths, store })(namespace);
}
};