Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more robust dynamic data retrieval from element #1535

Merged
merged 1 commit into from
Feb 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions packages/subapp-web/src/subapp-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,7 @@
}

if (!runtimeInfo.bundleAssets) {
try {
// TODO: right way to extract JSON from script tag?
runtimeInfo.bundleAssets = JSON.parse(document.getElementById("bundleAssets").innerHTML);
} catch (err) {
console.log("ERROR: fail retrieve bundleAssets", err);
return;
}
runtimeInfo.bundleAssets = xv1.dyn("bundleAssets");
}

const ba = runtimeInfo.bundleAssets;
Expand All @@ -315,8 +309,9 @@
}, a);
}, [])
.filter(({ id }) => {
if (xv1.getBundle(id.toString()) === undefined) {
xv1.setBundle(id.toString(), 0); // mark as loading
id = id.toString();
if (xv1.getBundle(id) === undefined) {
xv1.setBundle(id, 0); // mark as loading

return true;
}
Expand All @@ -342,6 +337,21 @@
}
});
});
},

dyn(id) {
const msg = "ERROR: fail retrieve dynamic data from element";
const element = document.getElementById(id);
if (!id) {
console.error(msg, id, "- get");
} else {
try {
return JSON.parse(element.innerHTML);
} catch (err) {
console.error(msg, "- parse");
return {};
}
}
}
});
})(window);