Created
February 13, 2023 15:50
-
-
Save paulsonnentag/e608c735aa6e5e468ecad6d6bc68ed8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import ReactDOM from 'react-dom/client' | |
import {RoomDB} from "./roomdb.js"; | |
const root = ReactDOM.createRoot(document.getElementById('root')) | |
const db = new RoomDB(); | |
db.claim(["Aachen", "lat", 50.775555]) | |
db.claim(["Aachen", "long", 50.775555]) | |
db.claim(["Chicago", "lat", 41.881832]) | |
db.claim(["Chicago", "long", -87.623177]) | |
function App() { | |
return ( | |
<div> | |
<h1>App</h1> | |
<div>{db.allFacts().map((fact, index) => ( | |
<div key={index}>{JSON.stringify(fact, null, 2)}</div> | |
))}</div> | |
</div> | |
) | |
} | |
function loop() { | |
db.batch(() => { | |
db.retract(["*", "temperature", "*"]) | |
db.select(["$point", "lat", "$lat"] | |
).do(({point}) => { | |
// todo: do actual lookup | |
db.claim([point, "temperature", Math.random()]) | |
}) | |
}) | |
root.render(<App />) | |
requestAnimationFrame(loop) | |
} | |
loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment