@@ -142,7 +142,7 @@ type ready = {
142
142
type state =
143
143
| Init
144
144
| SetupFailed (string )
145
- | SwitchingCompiler (ready , string , array (string ))
145
+ | SwitchingCompiler (ready , string , array (string )) // (ready, targetId, libraries)
146
146
| Ready (ready )
147
147
| Compiling (ready , (Lang . t , string ));
148
148
@@ -159,13 +159,19 @@ type action =
159
159
| CompileCode (Lang . t , string )
160
160
| UpdateConfig (Config . t );
161
161
162
- // onAction: This function is especially useful if you want to maintain
163
- // state that depends on any action happening in the compiler, no
164
- // matter if a state transition happened, or not.
165
- // We need that for a ActivityIndicator component to give feedback
166
- // to the user that an action happened (useful in cases where the output
167
- // didn't visually change)
168
- let useCompilerManager = (~onAction: option (action => unit )=?, () ) => {
162
+ // ~initialLang:
163
+ // The target language the compiler should be set to during
164
+ // playground initialization. If the compiler doesn't support the language, it
165
+ // will default to ReScript syntax
166
+ //
167
+ // ~onAction:
168
+ // This function is especially useful if you want to maintain state that
169
+ // depends on any action happening in the compiler, no matter if a state
170
+ // transition happened, or not. We need that for a ActivityIndicator
171
+ // component to give feedback to the user that an action happened (useful in
172
+ // cases where the output didn't visually change)
173
+ let useCompilerManager =
174
+ (~initialLang: Lang . t =Res , ~onAction: option( action => unit) =?, () ) => {
169
175
let (state , setState ) = React . useState(_ => Init );
170
176
171
177
// Dispatch method for the public interface
@@ -365,10 +371,17 @@ let useCompilerManager = (~onAction: option(action => unit)=?, ()) => {
365
371
instance,
366
372
};
367
373
374
+ let targetLang =
375
+ Version . availableLanguages(apiVersion)
376
+ -> Js . Array2 . find(l => {l === initialLang})
377
+ -> Belt . Option . getWithDefault(
378
+ Version . defaultTargetLang(apiVersion),
379
+ );
380
+
368
381
setState(_ => {
369
382
Ready ({
370
383
selected,
371
- targetLang: Version . defaultTargetLang(apiVersion) ,
384
+ targetLang,
372
385
versions,
373
386
errors: [||] ,
374
387
result: FinalResult . Nothing ,
0 commit comments