Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit 9148fcc

Browse files
committed
Some non-breaking changes and minor tidy to the (still broken) test suite.
1 parent 75cd1a0 commit 9148fcc

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

pyscript.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
};

spec/pyscriptSpec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe("In the PyScript project,", function() {
3838
result = e.detail;
3939
};
4040
document.addEventListener("py-configured", checkEvent);
41-
pyscript.loadConfig();
41+
pyscript.start();
4242
expect(result.runtime).toEqual("micropython");
4343
expect(result.mp_memory).toEqual(65536);
4444
});
@@ -49,7 +49,7 @@ describe("In the PyScript project,", function() {
4949
result = e.detail;
5050
};
5151
document.addEventListener("py-configured", checkEvent);
52-
pyscript.loadConfig();
52+
pyscript.start();
5353
expect(result).toBeDefined()
5454
});
5555

@@ -64,15 +64,15 @@ describe("In the PyScript project,", function() {
6464
it("registerPlugin should configure the passed-in plugins, startPlugins should start them", function() {
6565
let configureFlag = false;
6666
let startFlag = false;
67-
class TestPlugin extends Plugin {
68-
configure(config) {
67+
const TestPlugin = {
68+
configure: function(config) {
6969
configureFlag = true;
70-
}
71-
start(config) {
70+
},
71+
start: function(config) {
7272
startFlag = true;
7373
}
7474
}
75-
pyscript.registerPlugin(new TestPlugin());
75+
pyscript.registerPlugin(TestPlugin);
7676
expect(configureFlag).toEqual(true);
7777
pyscript.startPlugins();
7878
expect(startFlag).toEqual(true);

0 commit comments

Comments
 (0)