To be able to edit code and run cells, you need to run the notebook yourself. Where would you like to run the notebook?

This notebook takes about 30 seconds to run.

In the cloud (experimental)

Binder is a free, open source service that runs scientific notebooks in the cloud! It will take a while, usually 2-7 minutes to get a session.

On your computer

(Recommended if you want to store your changes.)

  1. Copy the notebook URL:
  2. Run Pluto

    (Also see: How to install Julia and Pluto)

  3. Paste URL in the Open box

Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Author 1
👀 Reading hidden code
using JSON
87.7 ms

Modify x, add and remove elements, and notice that preact maintains its state.

👀 Reading hidden code
193 μs
👀 Reading hidden code
x = ["hi!", "pluto is cool", 232,2,2,12 ,12,2,21,1,2]
29.7 ms
👀 Reading hidden code
HTML("""
<script type="module" id="asdf">
//await new Promise(r => setTimeout(r, 1000))
const { html, render, Component, useEffect, useLayoutEffect, useState, useRef, useMemo, createContext, useContext, } = await import( "https://cdn.jsdelivr.net/npm/htm@3.0.4/preact/standalone.mjs")

const node = this ?? document.createElement("div")
const new_state = $(json(state))
if(this == null){
const Item = ({value}) => {
const [loading, set_loading] = useState(true)

useEffect(() => {
set_loading(true)

const handle = setTimeout(() => {
set_loading(false)
}, 1000)

return () => clearTimeout(handle)
}, [value])

return html`<li>\${loading ?
html`<em>Loading...</em>` :
value
}</li>`
}

const App = () => {

const [state, set_state] = useState(new_state)
node.set_app_state = set_state

return html`<h1>Hello world!</h1>
<ul>\${
state.x.map((x,i) => html`<\${Item} value=\${x} key=\${i}/>`)
}</ul>`;
}



render(html`<\${App}/>`, node);
} else {
node.set_app_state(new_state)
}
return node
</script>
""")
181 ms
state = Dict(
:x => x
)
👀 Reading hidden code
20.3 μs