Skip to content

Instantly share code, notes, and snippets.

@FlorianRappl
Created November 18, 2019 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlorianRappl/99e3c16bb78796ccdf2af5d4b129ce9b to your computer and use it in GitHub Desktop.
Save FlorianRappl/99e3c16bb78796ccdf2af5d4b129ce9b to your computer and use it in GitHub Desktop.
// app-shell/main.js
window.app = {
registerPage(url, cb) {}
// ...
};
showLoading();
fetch("https://feed.piral.io/api/v1/pilet/sample")
.then(res => res.json())
.then(body =>
Promise.all(
body.items.map(
item =>
new Promise(resolve => {
const script = document.createElement("script");
script.src = item.link;
script.onload = resolve;
document.body.appendChild(script);
})
)
)
)
.catch(err => console.error(err))
.then(() => hideLoading());
// module/index.jsx
import * as React from "react";
import { render } from "react-dom";
import { Page } from "./Page";
if (window.app !== undefined) {
window.app.registerPage("/sample", element => {
render(<Page />, element);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment