Published
Edited
Jun 12, 2022
Also listed in…
Croquet
Tips and Utilities
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
C = require("@croquet/croquet@1.0").catch(e => window.Croquet)
Insert cell
class MyModel extends C.Model {
init() {
this.count = 0;
this.subscribe("counter", "reset", this.resetCounter);
this.future(1000).tick();
}

resetCounter() {
this.count = 0;
this.publish("counter", "changed");
}

tick() {
this.count++;
this.publish("counter", "changed");
this.future(1000).tick();
}
}
Insert cell
MyModel.register("MyModel");
Insert cell
class MyView extends C.View {
constructor(model) {
super(model);
this.model = model;
countDisplay.onclick = event => this.counterReset();
this.subscribe("counter", "changed", this.counterChanged);
this.counterChanged();
}

counterReset() {
this.publish("counter", "reset");
}

counterChanged() {
countDisplay.textContent = this.model.count;
}
}
Insert cell
appId = 'com.gmail.triptych.microverse';
Insert cell
name = C.App.autoSession();
Insert cell
password = C.App.autoPassword();
Insert cell
apiKey = "1rix6FFjJlghdFLbJN6p47xIu4e5NH4ooNPl6gKDA"
Insert cell
C.Session.join({
apiKey: apiKey,
appId,
name,
password,
model: MyModel, view: MyView});
Insert cell
countDisplay = html`<div class="cd"></div>`
Insert cell
html`<style>
.cd {
font: 64px sans-serif;
background-color: #fcfcfc;
height: 300px;
}

</style>`
Insert cell
Insert cell
import { embed } from "@jerryjappinen/embed"
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