Published
Edited
Dec 16, 2019
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
viewof option1 = DOM.select(none_doc);
Insert cell
Insert cell
problem = {
const root = html`<div></div>`;
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state = {isToggleOn: true};

// This binding is necessary to make `this` work in the callback
this.handleClick = this.handleClick.bind(this);
}

handleClick() {
this.setState(state => ({
isToggleOn: !state.isToggleOn
}));

}

render() {
return htm`
<button onClick=${this.handleClick}>
${this.state.isToggleOn? "ON" : "OFF"}
</button>
`;
}
}

ReactDOM.render(
htm`<${Toggle} />`,
root
);
return root;
}
Insert cell
{
const root = html`<div></div>`;
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state = {isToggleOn: true};

// This binding is necessary to make `this` work in the callback
// this.handleClick = this.handleClick.bind(this);
}

handleClick() {
this.setState(state => ({
isToggleOn: !state.isToggleOn
}));

}

render() {
return htm`
<button onClick=${e => this.handleClick(e)}>
${this.state.isToggleOn? "ON" : "OFF"}
</button>
`;
}
}

ReactDOM.render(
htm`<${Toggle} />`,
root
);
return root;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable list = [];
Insert cell
// toc = html`<ol>
// ${list.sort((a, b) => a.idx - b.idx).map((d, idx) =>
// html`
// <li>
// <a href=${"#"+d.id}>${d.id + " =>"}</a>
// <span>${d.des}</span>
// </li>`)}
// </ol>`
Insert cell
html`<table style="width: 180px;">
<thead><tr><th>#</th><th>Color</th><th>Swatch</th></tr></thead>
<tbody>${d3.schemeCategory10.map((color, i) => html`<tr>
<td>${i}</td>
<td>${color}</td>
<td style=${{background: color}}></td>
</tr>`)}</tbody>
</table>`
Insert cell
function addList(id, des, idx) {
let list = mutable list;
// todo: make sure no replicate of id
list.push({id: id, des: des, idx: idx});
mutable list = list;
}
Insert cell
d3 = require("d3")
Insert cell
import {html, svg} from "@observablehq/htl"
Insert cell
import {React, ReactDOM, htm, none_doc, hide_display} from "@embracelife/tutorial-utilities"
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