Public
Edited
Dec 19, 2023
1 fork
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
(await Purescript(hi)).module.hi
Insert cell
Insert cell
Insert cell
Insert cell
ps = await Purescript(source)
Insert cell
module = ps.module
Insert cell
Insert cell
Insert cell
module.val
Insert cell
Insert cell
Insert cell
module.greet("me")
Insert cell
Insert cell
Insert cell
module.main()
Insert cell
Insert cell
An html string
Insert cell
module.render.toString()
Insert cell
Insert cell
unsafe_html`${module.render}`
Insert cell
function unsafe_html() {
const span = document.createElement("span");
span.innerHTML = String.raw.apply(this, arguments);
return span;
}
Insert cell
Insert cell
Insert cell
warnings = ps.warnings
Insert cell
Insert cell
Insert cell
errors = (await Purescript(`wat?`)).errors
Insert cell
Insert cell
(await Purescript(hi, { compilerUrl: "http://127.0.0.1:8080" })).module.hi
Insert cell
Insert cell
(await Purescript(simpleSample, { compilerUrl: "http://127.0.0.1:8080" })).module.val
Insert cell
(await Purescript("module Main where\n import Data.Codec.Foreign (_stringify)\n stringify = _stringify", { compilerUrl: "http://127.0.0.1:8080" })).module.stringify(true)
Insert cell
Insert cell
Insert cell
Insert cell
// returns Promise<{errors?, warnings?, module?}>
Purescript = async (source, options = { compilerUrl: "https://compile.purescript.org" }) => {
const { compilerUrl } = options
let response = await compile(source, compilerUrl)
if (response.error && response.error.contents)
return { errors: response.error && response.error.contents, warnings: response.warnings }
// console.log("compilerUrl", compilerUrl);
let jsPatched = response.js.replaceAll('from "../', `from "${compilerUrl}/output/`)
// console.log("jsPatched", jsPatched)
let sourceURL = URL.createObjectURL(new Blob([jsPatched], { type: 'text/javascript' }))
// console.log(sourceURL)
let module
try {
module = await import(sourceURL)
} catch (e) {
console.error(e)
return { module: e }
}
return { module, warnings: response.warnings }
}
Insert cell
compile = (source, compilerUrl) => fetch(`${compilerUrl}/compile`, {
method: 'POST',
body: `${source}`
}).then((response) => response.json());
Insert cell
Insert cell
// jsPatched = response.js.replaceAll('from "../', 'from "https://compile.purescript.org/output/')
Insert cell
Insert cell
// sourceURL = URL.createObjectURL(new Blob([jsPatched], { type: 'text/javascript' }))
Insert cell
Insert cell
// module = import(sourceURL)
Insert cell
Insert cell
Insert cell
import {mdPlus} from "@tmcw/bonus-markdown-flavor"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more