File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed
docs-site/src/components/Example Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -62,35 +62,36 @@ export default class CodeExampleComponent extends React.Component<
62
62
registerLocale ( "en-GB" , enGB ) ;
63
63
}
64
64
65
- transpileTsCode = async ( ) => {
66
- const tsCode = this . state . tsxCode ;
65
+ applyStateUpdates = ( stateUpdates : Partial < TState > ) => {
66
+ this . setState ( ( state ) => ( {
67
+ ...state ,
68
+ ...stateUpdates ,
69
+ } ) ) ;
70
+ } ;
67
71
68
- let stateUpdates = {
72
+ transpileTsCode = async ( ) => {
73
+ this . applyStateUpdates ( {
69
74
jsxCode : "" ,
70
75
isTranspiling : true ,
71
- } ;
76
+ } ) ;
72
77
73
78
try {
79
+ const tsCode = this . state . tsxCode ;
74
80
const transpiledCode = await transformTsx ( tsCode ) ;
75
81
76
82
this . lastTranspiledTsCodeRef . current = tsCode ;
77
- stateUpdates = {
83
+ this . applyStateUpdates ( {
78
84
jsxCode : transpiledCode ,
79
85
isTranspiling : false ,
80
- } ;
86
+ } ) ;
81
87
} catch ( err ) {
82
- stateUpdates = {
88
+ this . applyStateUpdates ( {
83
89
jsxCode : "// Transpilation failed! Error: " + ( err as Error ) . message ,
84
90
isTranspiling : false ,
85
- } ;
91
+ } ) ;
86
92
87
93
toast . show ( "Transpilation failed!" , "error" ) ;
88
94
}
89
-
90
- this . setState ( ( state ) => ( {
91
- ...state ,
92
- ...stateUpdates ,
93
- } ) ) ;
94
95
} ;
95
96
96
97
handleCodeChange = debounce ( ( code : string ) => {
You can’t perform that action at this time.
0 commit comments