Published
Edited
Mar 20, 2020
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
view = jsx`state => <button $onclick={state=>state+1}>
Clicks: {state}
</button>`
Insert cell
app.start(document.createElement('div'), 0, view).element
Insert cell
Insert cell
view2 = jsx`state => <>
<div>{state.text}</div>
<input $bind="text" placeholder="type something here ..."/>
</>
`
Insert cell
app.start(document.createElement('div'), {}, view2).element
Insert cell
Insert cell
state = ({
a: 1,
b: 2,
get c() {
return this.a + this.b;
}
})
Insert cell
Insert cell
view3 = jsx`({a, b, c}) => <>
<input type="number" $bind="a" />
<input type="number" $bind="b" />
<p>{a} + {b} = { c }</p>
</>`
Insert cell
app.start(document.createElement('div'), state, view3).element
Insert cell
Insert cell
handler = ({
get: (target, name) => {
const text = target.text || '';
switch (name) {
case 'text': return target.text;
case 'characters': return text.replace(/\s/g, '').length;
case 'words': return !text ? 0 : text.split(/\s/).length;
case 'lines': return text.split('\n').length;
default: return null
}
}
})
Insert cell
proxy = new Proxy(
{ text: "let's count" },
handler
);
Insert cell
Insert cell
view5 = jsx`state => <div>
<textarea rows="10" cols="50" $bind="text"></textarea>
<div>{state.characters} {state.words} {state.lines}</div>
{state.text}
</div>`
Insert cell
app.start(document.createElement('div'), proxy, view5).element
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more