Skip to content

Commit

Permalink
update: universaly named variable
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Feb 6, 2024
1 parent 533d820 commit a97d88d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions extensions/src/data_bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ const plugin: JupyterFrontEndPlugin<void> = {
};

// @ts-ignore
window.requestDataFromHost = () => {
window.requestDataFromHost = (variableName = "data") => {
window.parent.postMessage(
{
type: "from-iframe-to-host",
requestData: true,
variableName,
},
"*"
);
Expand All @@ -61,11 +62,12 @@ const plugin: JupyterFrontEndPlugin<void> = {
window.addEventListener("message", async (event) => {
if (event.data.type === "from-host-to-iframe") {
let data = event.data.data;
let variableName = event.data.variableName;
const dataJson = JSON.stringify(data);
const code = `
import json
data = json.loads('${dataJson}')
`;
import json
${variableName} = json.loads('${dataJson}')
`;
// Similar to https://jupyterlab.readthedocs.io/en/stable/api/classes/application.LabShell.html#currentWidget
// https://jupyterlite.readthedocs.io/en/latest/reference/api/ts/interfaces/jupyterlite_application.ISingleWidgetShell.html#currentwidget
const currentWidget = app.shell.currentWidget;
Expand Down

0 comments on commit a97d88d

Please sign in to comment.