@@ -437,16 +437,14 @@ module SettingsPanel = {
437437 let make = (
438438 ~activeTab : Signal .t <tab >,
439439 ~compilerInfo : Signal .t <option <CompilerApi .info >>,
440- ~compilerVersion : Signal .t <string >,
441- ~moduleSystem : Signal .t <moduleSystem >,
442- ~warnFlags : Signal .t <string >,
443- ~jsxPreserveMode : Signal .t <bool >,
444- ~experimentalFeatures : Signal .t <array <experimentalFeature >>,
440+ ~config : Signal .t <PlaygroundConfig .t >,
445441 ~switchCompiler : string => unit ,
446442 ~compileNow : unit => unit ,
447443 ~scheduleCompile : unit => unit ,
448444 ~scheduleUrlSync : unit => unit ,
449445 ) => {
446+ let updateConfig = f => Signal .update (config , f )
447+
450448 <div
451449 class = {() =>
452450 Signal .get (activeTab ) === Settings ? "settings-panel" : "settings-panel hidden-panel" }
@@ -457,10 +455,10 @@ module SettingsPanel = {
457455 </label >
458456 <select
459457 id = "compiler-version"
460- value = {ReactiveProp . reactive ( compilerVersion ) }
458+ value = {() => Signal . get ( config ). compilerVersion }
461459 onChange = {event => {
462460 let nextVersion = Event .value (event )
463- Signal . set ( compilerVersion , nextVersion )
461+ updateConfig ( config => { ... config , compilerVersion : nextVersion } )
464462 switchCompiler (nextVersion )
465463 }}
466464 >
@@ -486,11 +484,11 @@ module SettingsPanel = {
486484 <label class = "setting-label" for_ = "module-system" > {Node .text ("Module System" )} </label >
487485 <select
488486 id = "module-system"
489- value = {() => (Signal .get (moduleSystem ) :> string )}
487+ value = {() => (Signal .get (config ). moduleSystem :> string )}
490488 onChange = {event => {
491489 switch event -> Event .value -> parseModuleSystem {
492490 | Some (nextModuleSystem ) =>
493- Signal . set ( moduleSystem , nextModuleSystem )
491+ updateConfig ( config => { ... config , moduleSystem : nextModuleSystem } )
494492 scheduleUrlSync ()
495493 compileNow ()
496494 | None => ()
@@ -509,18 +507,18 @@ module SettingsPanel = {
509507 <label class = "setting-label" for_ = "warning-flags" > {Node .text ("Warning Flags" )} </label >
510508 <input
511509 id = "warning-flags"
512- value = {ReactiveProp . reactive ( warnFlags ) }
510+ value = {() => Signal . get ( config ). warnFlags }
513511 spellcheck = false
514512 onInput = {event => {
515- Signal . set ( warnFlags , Event .value (event ))
513+ updateConfig ( config => { ... config , warnFlags : Event .value (event )} )
516514 scheduleUrlSync ()
517515 scheduleCompile ()
518516 }}
519517 />
520518 <button
521519 class = "secondary-action"
522520 onClick = {_ => {
523- Signal . set ( warnFlags , CompilerApi .defaultWarnFlags )
521+ updateConfig ( config => { ... config , warnFlags : CompilerApi .defaultConfig . warnFlags } )
524522 scheduleUrlSync ()
525523 compileNow ()
526524 }}
@@ -532,9 +530,9 @@ module SettingsPanel = {
532530 <input
533531 id = "jsx-preserve"
534532 type_ = "checkbox"
535- checked = {ReactiveProp . reactive ( jsxPreserveMode ) }
533+ checked = {() => Signal . get ( config ). jsxPreserveMode }
536534 onChange = {event => {
537- Signal . set ( jsxPreserveMode , Event .checked (event ))
535+ updateConfig ( config => { ... config , jsxPreserveMode : Event .checked (event )} )
538536 scheduleUrlSync ()
539537 compileNow ()
540538 }}
@@ -545,9 +543,12 @@ module SettingsPanel = {
545543 <input
546544 id = "feature-let-unwrap"
547545 type_ = "checkbox"
548- checked = {() => Signal .get (experimentalFeatures ) -> hasFeature (LetUnwrap )}
546+ checked = {() => Signal .get (config ). experimentalFeatures -> hasFeature (LetUnwrap )}
549547 onChange = {_ => {
550- Signal .update (experimentalFeatures , features => toggleFeature (features , LetUnwrap ))
548+ updateConfig (config => {
549+ ... config ,
550+ experimentalFeatures : toggleFeature (config .experimentalFeatures , LetUnwrap ),
551+ })
551552 scheduleUrlSync ()
552553 compileNow ()
553554 }}
@@ -593,26 +594,12 @@ module StatusBadge = {
593594module App = {
594595 @jsx.component
595596 let make = () => {
596- let defaultConfig = {
597- PlaygroundConfig .compilerVersion : CompilerApi .defaultCompilerVersion ,
598- moduleSystem : Esmodule ,
599- warnFlags : CompilerApi .defaultWarnFlags ,
600- jsxPreserveMode : false ,
601- experimentalFeatures : [],
602- }
603-
604597 let source = Signal .make (defaultSource )
605598 let activeTab = Signal .make (JavaScript )
606599 let status = Signal .make (Loading )
607600 let compilerInfo : Signal .t <option <CompilerApi .info >> = Signal .make (None )
608601 let compileResult : Signal .t <option <CompilerApi .compileResult >> = Signal .make (None )
609- let compilerVersion = Signal .make (defaultConfig .compilerVersion )
610- let moduleSystem = Signal .make (defaultConfig .moduleSystem )
611- let warnFlags = Signal .make (defaultConfig .warnFlags )
612- let jsxPreserveMode = Signal .make (defaultConfig .jsxPreserveMode )
613- let experimentalFeatures : Signal .t <array <experimentalFeature >> = Signal .make (
614- defaultConfig .experimentalFeatures ,
615- )
602+ let config = Signal .make (CompilerApi .defaultConfig )
616603 let activeLine = Signal .make (1 )
617604 let editorScrollTop = Signal .make (0 )
618605 let editorScrollLeft = Signal .make (0 )
@@ -641,14 +628,6 @@ module App = {
641628 Signal .set (editorScrollLeft , Event .scrollLeft (event ))
642629 }
643630
644- let currentConfig = () => {
645- PlaygroundConfig .compilerVersion : Signal .peek (compilerVersion ),
646- moduleSystem : Signal .peek (moduleSystem ),
647- warnFlags : Signal .peek (warnFlags ),
648- jsxPreserveMode : Signal .peek (jsxPreserveMode ),
649- experimentalFeatures : Signal .peek (experimentalFeatures ),
650- }
651-
652631 let compileNow = () => {
653632 compileSequence := compileSequence .contents + 1
654633 let sequence = compileSequence .contents
@@ -660,7 +639,7 @@ module App = {
660639 | Ready | Compiling =>
661640 Signal .set (status , Compiling )
662641 try {
663- let result = await CompilerApi .compile (Signal .peek (source ), currentConfig ( ))
642+ let result = await CompilerApi .compile (Signal .peek (source ), Signal . peek ( config ))
664643 if sequence === compileSequence .contents {
665644 Signal .set (compileResult , Some (result ))
666645 Signal .set (status , Ready )
@@ -690,7 +669,7 @@ module App = {
690669 }
691670
692671 let syncUrlNow = () =>
693- UrlState .replace (~source = Signal .peek (source ), ~config = currentConfig ( ))-> Promise .ignore
672+ UrlState .replace (~source = Signal .peek (source ), ~config = Signal . peek ( config ))-> Promise .ignore
694673
695674 let scheduleUrlSync = () => {
696675 switch urlTimerId .contents {
@@ -712,7 +691,7 @@ module App = {
712691 | Ready | Compiling =>
713692 Signal .set (status , Compiling )
714693 try {
715- switch await CompilerApi .format (sourceBeforeFormat , currentConfig ( )) {
694+ switch await CompilerApi .format (sourceBeforeFormat , Signal . peek ( config )) {
716695 | Ok (formattedSource ) =>
717696 if sequence === compileSequence .contents {
718697 if Signal .peek (source ) === sourceBeforeFormat {
@@ -765,7 +744,7 @@ module App = {
765744 }
766745
767746 let share = async () => {
768- switch await UrlState .copy (~source = Signal .peek (source ), ~config = currentConfig ( )) {
747+ switch await UrlState .copy (~source = Signal .peek (source ), ~config = Signal . peek ( config )) {
769748 | Ok () => showToast ("Link copied" )
770749 | Error (message ) => showToast (message )
771750 }
@@ -787,8 +766,8 @@ module App = {
787766 if sequence === compilerLoadSequence .contents {
788767 let firstLoadConfigValue = firstLoadConfig .contents
789768 firstLoadConfig := None
790- let config = switch firstLoadConfigValue {
791- | Some (config ) => config
769+ let nextConfig = switch firstLoadConfigValue {
770+ | Some (config ) => { ... config , compilerVersion : info . bundleId }
792771 | None => {
793772 PlaygroundConfig .compilerVersion : info .bundleId ,
794773 moduleSystem : info .moduleSystem ,
@@ -798,11 +777,7 @@ module App = {
798777 }
799778 }
800779 Signal .set (compilerInfo , Some (info ))
801- Signal .set (compilerVersion , info .bundleId )
802- Signal .set (moduleSystem , config .moduleSystem )
803- Signal .set (warnFlags , config .warnFlags )
804- Signal .set (jsxPreserveMode , config .jsxPreserveMode )
805- Signal .set (experimentalFeatures , config .experimentalFeatures )
780+ Signal .set (config , nextConfig )
806781 Signal .set (status , Ready )
807782 switch firstLoadConfigValue {
808783 | Some (_ ) => ()
@@ -831,17 +806,9 @@ module App = {
831806
832807 Effect .run (() => {
833808 let start = async () => {
834- let urlState = await UrlState .init (
835- ~defaultSource ,
836- ~defaultConfig ,
837- ~availableCompilerVersions = CompilerApi .availableCompilerVersions ,
838- )
809+ let urlState = await UrlState .init (~defaultSource )
839810 Signal .set (source , urlState .source )
840- Signal .set (compilerVersion , urlState .config .compilerVersion )
841- Signal .set (moduleSystem , urlState .config .moduleSystem )
842- Signal .set (warnFlags , urlState .config .warnFlags )
843- Signal .set (jsxPreserveMode , urlState .config .jsxPreserveMode )
844- Signal .set (experimentalFeatures , urlState .config .experimentalFeatures )
811+ Signal .set (config , urlState .config )
845812 Signal .set (activeLine , 1 )
846813 Signal .set (editorScrollTop , 0 )
847814 Signal .set (editorScrollLeft , 0 )
@@ -961,17 +928,7 @@ module App = {
961928 <Problems compileResult />
962929 </div >
963930 <SettingsPanel
964- activeTab
965- compilerInfo
966- compilerVersion
967- moduleSystem
968- warnFlags
969- jsxPreserveMode
970- experimentalFeatures
971- switchCompiler
972- compileNow
973- scheduleCompile
974- scheduleUrlSync
931+ activeTab compilerInfo config switchCompiler compileNow scheduleCompile scheduleUrlSync
975932 />
976933 </div >
977934 </section >
0 commit comments