@@ -508,6 +508,26 @@ const main = function() {
508
508
}
509
509
}
510
510
511
+ /**************************************************************************
512
+ Utility functions for MicroPyScript.
513
+ **************************************************************************/
514
+
515
+ function toJSON ( node ) {
516
+ /*
517
+ Takes a node in the DOM and serialises it into JSON.
518
+ */
519
+ }
520
+
521
+ function toDOM ( obj ) {
522
+ /*
523
+ Takes a JSON object and returns a node to mutate into the DOM.
524
+ */
525
+ }
526
+
527
+ /**************************************************************************
528
+ Variables and functions needed for the life-cycle of MicroPyScript.
529
+ **************************************************************************/
530
+
511
531
// Default configuration settings for MicroPyScript. These may be overridden
512
532
// by the app.loadConfig function.
513
533
// The "files" object should look like this:
@@ -674,8 +694,10 @@ const main = function() {
674
694
// setup.
675
695
Promise . all ( pendingDownloads ) . then ( ( values ) => {
676
696
filesLoaded = true ;
677
- if ( values ) {
678
- logger ( `All files downloaded, copying to filesystem. 📥` ) ;
697
+ if ( values . length > 0 ) {
698
+ logger ( `${ values . length } file[s] downloaded, copying to filesystem. 📥` ) ;
699
+ } else {
700
+ logger ( `No files to download, nothing to do on filesystem. 📥` ) ;
679
701
}
680
702
const pyFilesLoaded = new CustomEvent ( "py-files-loaded" ) ;
681
703
document . dispatchEvent ( pyFilesLoaded ) ;
@@ -687,8 +709,8 @@ const main = function() {
687
709
/*
688
710
Save the file's content to the path on the interpreter's local filesystem.
689
711
*/
690
- logger ( `Saving file "${ e . detail . path } " to file system. 💾` ) ;
691
712
interpreter . addFile ( e . detail . path , e . detail . content ) ;
713
+ logger ( `Saved file "${ e . detail . path } " to file system. 💾` ) ;
692
714
}
693
715
694
716
function loadInterpreter ( ) {
@@ -805,13 +827,8 @@ const main = function() {
805
827
806
828
// Finally, return a function to start MicroPyScript.
807
829
return function ( ) {
808
- document . addEventListener ( "py-configured" , onPyConfigured ) ;
809
- document . addEventListener ( "py-interpreter-loaded" , onInterpreterLoaded ) ;
810
- document . addEventListener ( "py-file-fetched" , onFileFetched ) ;
811
- document . addEventListener ( "py-interpreter-ready" , onInterpreterReady ) ;
812
- document . addEventListener ( "py-finished-setup" , onFinished ) ;
813
- // An object to represent the MicroPyScript platform in the browser. What
814
- // is eventually returned from the main() function.
830
+ // An object to represent the MicroPyScript platform in the browser.
831
+ // What is eventually returned from the main() function.
815
832
const pyScript = {
816
833
get config ( ) {
817
834
return config ;
@@ -837,6 +854,11 @@ const main = function() {
837
854
}
838
855
} ,
839
856
start : function ( ) {
857
+ document . addEventListener ( "py-configured" , onPyConfigured ) ;
858
+ document . addEventListener ( "py-interpreter-loaded" , onInterpreterLoaded ) ;
859
+ document . addEventListener ( "py-file-fetched" , onFileFetched ) ;
860
+ document . addEventListener ( "py-interpreter-ready" , onInterpreterReady ) ;
861
+ document . addEventListener ( "py-finished-setup" , onFinished ) ;
840
862
loadConfig ( ) ;
841
863
}
842
864
} ;
0 commit comments