Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Pull code from remote source #10

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
use promises
  • Loading branch information
faraazahmad committed Oct 16, 2023
commit f4efb11e18c9f80faba537cedf4590a0de1c6231
15 changes: 6 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Promise.all([
// dang huge (> 40Mb). In the meantime the textarea that is holding the place
// of the actual functional one is just going to display "Loading...".
import("./createRuby").then(({ default: createRuby }) => createRuby())
]).then(async ([editor, mermaid, ruby]) => {
]).then(([editor, mermaid, ruby]) => {
// First, grab a reference to the output element so that we can update it.
// Then, set it initially to the output represented by the source.
const output = document.getElementById("output");
Expand Down Expand Up @@ -113,13 +113,10 @@ Promise.all([
// fetch code from URL
const params = new URLSearchParams(document.location.search)
const sourceURL = params.get('source')
try {
const response = await fetch(new URL(sourceURL))
if (response.status === 200) {
const data = await response.text()
editor.setValue(data)
}
} catch (error) {
console.error(error)
if (sourceURL) {
fetch(new URL(sourceURL))
.then(response => response.text())
.then(data => editor.setValue(data))
.catch(error => console.error(error))
}
});