@@ -4,8 +4,6 @@ import 'ace-builds/src-noconflict/mode-javascript';
4
4
import 'ace-builds/src-noconflict/theme-dracula' ;
5
5
import 'ace-builds/src-noconflict/theme-terminal' ;
6
6
7
- import * as esbuild from 'esbuild-wasm' ;
8
-
9
7
import React , { useContext , useEffect , useRef , useState } from 'react' ;
10
8
import {
11
9
codePreviewInput ,
@@ -19,22 +17,14 @@ import { RootState } from '../../redux/store';
19
17
import { fetchPlugin } from '../../plugins/fetch-plugin' ;
20
18
import { unpkgPathPlugin } from '../../plugins/unpkg-path-plugin' ;
21
19
import useResizeObserver from '../../tree/useResizeObserver' ;
20
+ import { initializeEsbuild } from '../../helperFunctions/esbuildService' ;
22
21
23
22
const CodePreview : React . FC < {
24
23
theme : string | null ;
25
24
setTheme : any | null ;
26
25
} > = ( { theme, setTheme } ) => {
27
26
const ref = useRef < any > ( ) ;
28
27
29
- /**
30
- * Starts the Web Assembly service.
31
- */
32
- const startService = async ( ) => {
33
- ref . current = await esbuild . initialize ( {
34
- worker : true ,
35
- wasmURL :
'https://unpkg.com/[email protected] /esbuild.wasm'
36
- } ) ;
37
- } ;
38
28
const dispatch = useDispatch ( ) ;
39
29
40
30
const wrapper = useRef ( ) ;
@@ -49,7 +39,8 @@ const CodePreview: React.FC<{
49
39
const [ input , setInput ] = useState ( '' ) ;
50
40
51
41
useEffect ( ( ) => {
52
- startService ( ) ;
42
+ //Starts the Web Assembly service
43
+ initializeEsbuild ( ) ;
53
44
} , [ ] ) ;
54
45
55
46
useEffect ( ( ) => {
@@ -61,6 +52,13 @@ const CodePreview: React.FC<{
61
52
dispatch ( codePreviewInput ( currentComponent . code ) ) ;
62
53
} , [ currentComponent , state . components ] ) ;
63
54
55
+ useEffect ( ( ) => {
56
+ console . log ( 'CodePreview Mounted' ) ;
57
+ return ( ) => {
58
+ console . log ( 'CodePreview Unmounted' ) ;
59
+ } ;
60
+ } , [ ] ) ;
61
+
64
62
/**
65
63
* Handler thats listens to changes in code editor
66
64
* @param {string } data - Code entered by the user
0 commit comments