Public
Edited
Nov 23, 2022
Importers
Vue Reactivity in Notebook
Vue Components in Notebook
Insert cell
Insert cell
Insert cell
Insert cell
counter = {
return {
value: 0,
array: []
}
}
Insert cell
{
counter.value++
counter.array.push(counter.value)
return html`Run this cell to modify the object`
}
Insert cell
Insert cell
counter
Insert cell
Insert cell
Insert cell
Insert cell
{
const root = htl.html`<div />`
Vue.createApp({
template: `<div>Unix Time: {{time}}</div>`,
setup(){
const time = VueUse.useTimestamp()
return {
time,
}
}
}).mount(root)
return root
}
Insert cell
Insert cell
Insert cell
updateWithYield = {
// update in delcaring cell
const time = VueUse.useTimestamp()
while(true){
yield time.value // this will be resumed every requestAnimationFrame()
}
}
Insert cell
mutable updateInOtherCell = 0
Insert cell
{
// update in other cell and use invalidation api to cancel listeners
const time = VueUse.useTimestamp()
const stop = Vue.watch(time, (newVal)=>{
mutable updateInOtherCell = newVal
})
invalidation.then(()=>{
stop()
})
return html`<p>update in other cell and use invalidation api to cancel listeners, <br />or it will be left in RAM and run forever (until you refresh the page)</p>`
}
Insert cell
Insert cell
effect = {
return (func)=>{
// this implementation need an additional argument for invalidation
/*const scope = Vue.effectScope()
const result = scope.run(func)
inval.then(()=>{
scope.stop()
})
return result*/
// this implementation get rid of the need for another argument
// check https://observablehq.com/@observablehq/invalidation
const scope = Vue.effectScope()
return Generators.observe(notify => {
notify(scope.run(func))
return ()=> scope.stop()
})
}
}
Insert cell
mutable time2 = 0
Insert cell
effect(()=>{
const time = VueUse.useTimestamp()
Vue.watch(time, (newVal)=>{
mutable time2 = newVal // comment/uncomment this line!
})
return html`try commenting out the code in watch, and notice <code>time2</code> stops/resumes updating.`
})
Insert cell
html`And for a more convenient way to use timestamp, write <code>now</code>: ${now}`
Insert cell
Insert cell
Insert cell
Vue = require('vue@3.2.45/dist/vue.global.prod.js').catch(() => window["Vue"])
Insert cell
VueUse = {
Vue;
await require('vue-demi@0.13.11/lib/index.iife.js').catch(() => window["VueDemi"])
await require('@vueuse/shared@9.3.1/index.iife.min.js').catch(()=>{})
await require('@vueuse/core@9.3.1/index.iife.min.js').catch(()=>{})
return window["VueUse"]
}
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