Created
October 13, 2020 19:41
-
-
Save ljmotta/6753467138dd5eb8483eac9ded142237 to your computer and use it in GitHub Desktop.
Base64Png Editor State Control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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