@@ -34,20 +34,19 @@ interface AppProps {
3434const defaultSource = tutorial ;
3535
3636const SOURCE_SAVE_TIMEOUT = 5 * 1000 ; // 5 seconds
37+ type Timeout = ReturnType < typeof setTimeout > ;
38+
39+ const saver = new FileSaver ( ) ;
3740
3841function App ( { initialText, initialEngine } : AppProps ) {
3942 const [ engine , setEngine ] = useState < SupportedEngine > (
4043 initialEngine ?? defaultEngine ,
4144 ) ;
4245
4346 const currentSourceRef = useRef < string | undefined > ( undefined ) ;
44- const saverRef = useRef < FileSaver > ( new FileSaver ( ) ) ;
45- const editorRef : RefObject <
46- import ( "./components/SplitEditor" ) . default | null
47- > = useRef ( null ) ;
48- const autoSaveTimeoutRef = useRef < ReturnType < typeof setTimeout > | undefined > (
49- undefined ,
50- ) ;
47+ const editorRef : RefObject < SplitEditor | null > = useRef ( null ) ;
48+ const autoSaveTimeoutRef = useRef < Timeout | undefined > ( undefined ) ;
49+ const initialSource = initialText ? initialText : defaultSource ;
5150
5251 useEffect ( ( ) => {
5352 return ( ) => {
@@ -57,7 +56,6 @@ function App({ initialText, initialEngine }: AppProps) {
5756 } ;
5857 } , [ ] ) ;
5958
60- const initialSource = initialText ? initialText : defaultSource ;
6159 return (
6260 < div className = "main-container" >
6361 < Navigation
@@ -70,9 +68,9 @@ function App({ initialText, initialEngine }: AppProps) {
7068 const dotSrc = currentSourceRef . current ;
7169 if ( dotSrc ) {
7270 if ( format === sourceFormatExtension ) {
73- saveSource ( dotSrc , saverRef . current ) ;
71+ saveSource ( dotSrc , saver ) ;
7472 } else {
75- exportAs ( dotSrc , format , { engine } , saverRef . current ) ;
73+ exportAs ( dotSrc , format , { engine } , saver ) ;
7674 }
7775 }
7876 } }
0 commit comments