@@ -508,6 +508,26 @@ const main = function() {
508508 }
509509 }
510510
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+
511531 // Default configuration settings for MicroPyScript. These may be overridden
512532 // by the app.loadConfig function.
513533 // The "files" object should look like this:
@@ -674,8 +694,10 @@ const main = function() {
674694 // setup.
675695 Promise . all ( pendingDownloads ) . then ( ( values ) => {
676696 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. 📥` ) ;
679701 }
680702 const pyFilesLoaded = new CustomEvent ( "py-files-loaded" ) ;
681703 document . dispatchEvent ( pyFilesLoaded ) ;
@@ -687,8 +709,8 @@ const main = function() {
687709 /*
688710 Save the file's content to the path on the interpreter's local filesystem.
689711 */
690- logger ( `Saving file "${ e . detail . path } " to file system. 💾` ) ;
691712 interpreter . addFile ( e . detail . path , e . detail . content ) ;
713+ logger ( `Saved file "${ e . detail . path } " to file system. 💾` ) ;
692714 }
693715
694716 function loadInterpreter ( ) {
@@ -805,13 +827,8 @@ const main = function() {
805827
806828 // Finally, return a function to start MicroPyScript.
807829 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.
815832 const pyScript = {
816833 get config ( ) {
817834 return config ;
@@ -837,6 +854,11 @@ const main = function() {
837854 }
838855 } ,
839856 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 ) ;
840862 loadConfig ( ) ;
841863 }
842864 } ;
0 commit comments