Skip to content

Instantly share code, notes, and snippets.

@ljmotta
Created October 13, 2020 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljmotta/6753467138dd5eb8483eac9ded142237 to your computer and use it in GitHub Desktop.
Save ljmotta/6753467138dd5eb8483eac9ded142237 to your computer and use it in GitHub Desktop.
Base64Png Editor State Control
const stateControl = useMemo(() => new Base64PngStateControl(), [originalContent]);
const undo = useCallback(() => {
stateControl.undo();
updateEditorStateWithCurrentEdit(stateControl.getCurrentBase64PngEdit());
}, [stateControl]);
const redo = useCallback(() => {
stateControl.redo();
updateEditorStateWithCurrentEdit(stateControl.getCurrentBase64PngEdit());
}, [stateControl]);
const updateEditorStateWithCurrentEdit = useCallback((edit?: Base64PngEdit) => {
if (edit) {
setInvert(edit.invert);
} else {
updateEditorToInitialState();
}
}, []);
const updateEditorToInitialState = useCallback(() => {
setInvert(INITIAL_INVERT);
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment