Don't pyimport repr multiple times

This commit is contained in:
Michael Droettboom 2018-05-30 20:29:18 -04:00
parent 3831cf86fc
commit 7b6053ed13
2 changed files with 4 additions and 14 deletions

View File

@ -75,16 +75,6 @@ var languagePluginLoader = new Promise((resolve, reject) => {
return promise;
};
////////////////////////////////////////////////////////////
// Callable Python object shim
let makeCallableProxy = (obj) => {
var clone = obj.clone();
function callProxy(args) {
return clone.call(Array.from(arguments), {});
};
return callProxy;
};
////////////////////////////////////////////////////////////
// Loading Pyodide
let wasmURL = `${baseURL}pyodide.asm.wasm`;
@ -112,7 +102,6 @@ var languagePluginLoader = new Promise((resolve, reject) => {
script.onload = () => {
window.pyodide = pyodide(Module);
window.pyodide.loadPackage = loadPackage;
window.pyodide.makeCallableProxy = makeCallableProxy;
};
document.head.appendChild(script);
};

View File

@ -127,9 +127,10 @@ EM_JS(int, pyproxy_init, (), {
get: function (jsobj, jskey) {
if (jskey === 'toString') {
return function() {
// TODO: Cache repr
var repr = pyodide.pyimport('repr');
return repr(jsobj);
if (window.pyodide.repr === undefined) {
window.pyodide.repr = window.pyodide.pyimport('repr');
}
return window.pyodide.repr(jsobj);
}
} else if (jskey === '$$') {
return jsobj['$$'];