-
Notifications
You must be signed in to change notification settings - Fork 9
history 관련 mathquill이 undefined되던 이슈
LeeSuKyeong edited this page Dec 20, 2020
·
2 revisions
구현했던 redo, undo가 간혹 undefined를 발생하는 문제가 있어서 해당 로직을 새로 작성했습니다.
history : string[]
historyIdx : number
기존 mathquill에는 hitory와 historyIdx를 두어 지금까지의 history를 저장해두고 idx를 조절하여 redo, undo 기능을 구현했습니다.
undo, redo 기능이 동작하여 새로운 latex를 mathquill에 전달하면서, editable mathquill
의 onchange가 동작하게 됩니다. 이 때, redux의 change action이 전달되면서 historyIdx가 증가하는 현상이 원인이었습니다.
이를 해결하기 위해서는 hitoryIdx를 사용하지 않도록 history 로직을 다시 작성해야했습니다.
현재 latex를 가리키는 latex
, undo 기능을 위해 이전 latex를 저장해두는 preLaTex
배열, redo 기능을 위해 이후 latex를 저장해두는 nextLaTex
배열을 두었습니다.
// clear 시
preLaTex: [...state.preLaTex, state.latex]
latex: '',
nextLaTex: [],
// redo 시 `array.pop()` 으로 현재 latex를 nextLaTex의 마지막으로 되돌리고 nextLaTex를 배열제거
preLaTex: [...state.preLaTex, state.latex]
latex: nextLatex.pop(),
// nextLaTex는 pop을 했으니 배열이 한개 제거된 상태
//undo 시 `array.pop()` 으로 현재 latex를 preLaTex의 마지막으로 되돌리고 preLaTex를 배열제거
nextLaTex: [...state.nextLaTex, state.latex]
latex: preLatex.pop(),
// preLaTex는 pop을 했으니 배열이 한개 제거된 상태
// change(새로운 latex 추가) 시, preLaTex에 현재 latex 추가, latex: 새로운 latex, nextLaTex로 돌아갈 일이 없으니 빈배열로 초기화
preLaTex: [...state.preLaTex, state.latex]
latex: newLaTex,
nextLaTex: [],
- MathML Getting Started
- LaTex와 MathML
- webpack과 babel설정
- webpack bundle파일 줄이기
- react-mathquill 정리
- redux setting 및 공부
- Localstorage 사용법
- Drag and drop 사용법
😄데일리 스크럼
- 11월 17일 화요일 스크럼
- 11월 18일 수요일 스크럼
- 11월 19일 목요일 스크럼
- 11얼 20일 금요일 스크럼
- 11얼 23일 월요일 스크럼
- 11월 24일 화요일 스크럼
- 11월 25일 수요일 스크럼
- 11월 26일 목요일 스크럼
- 11월 27일 금요일 스크럼
- 11월 30일 월요일 스크럼
- 12월 1일 화요일 스크럼
- 12월 2일 수요일 스크럼
- 12월 3일 목요일 스크럼
- 12월 4일 금요일 스크럼
- 12월 7일 월요일 스크럼
- 12월 8일 화요일 스크럼
- 12월 9일 수요일 스크럼
- 12월 10일 목요일 스크럼
- 12월 14일 월요일 스크럼
- 12월 15일 화요일 스크럼
- 12월 16일 수요일 스크럼
- 12월 17일 목요일 스크럼
- 12월 18일 금요일 스크럼