summaryrefslogtreecommitdiff
path: root/test.html
diff options
context:
space:
mode:
Diffstat (limited to 'test.html')
-rw-r--r--test.html73
1 files changed, 31 insertions, 42 deletions
diff --git a/test.html b/test.html
index 3a0d853..3623578 100644
--- a/test.html
+++ b/test.html
@@ -5,7 +5,7 @@
<p id="ID"></p>
- <h2 id="status">Unsubscribed</h2>
+ <h2 id="status"></h2>
<button onclick="Subscribe()">
Subscribe
@@ -31,7 +31,7 @@
import Graffiti from "./graffiti.js"
// Connect to a local Graffiti instance
- // (see the server README for how to run locally)
+ // (see the server README for how to n locally)
const graffiti = new Graffiti("http://localhost:5001")
await graffiti.initialize()
@@ -41,57 +41,46 @@
window.LogOut = ()=> graffiti.toggleLogIn()
document.getElementById('ID').innerHTML = `Your Graffiti ID is: ${graffiti.myID}`
- // Create a display counter
- let count = 0
- function displayCount() {
- document.getElementById('status').innerHTML = `Subscribed: ${count} Objects`
+ const myTag = "asdf"
+
+ // Make a display
+ async function displayObjects() {
+ await new Promise(r => setTimeout(r, 1000));
+
+ let display = 'not subscribed'
+ try {
+ const objects = graffiti.objectsByTags(myTag)
+ display = `objects: ${JSON.stringify(objects)}`
+ } catch {}
+
+ document.getElementById('status').innerHTML = display
+ }
+
+ // Create an object containing a special string
+ window.Subscribe = async function() {
+ await graffiti.subscribe(myTag)
+ displayObjects()
}
- // From here to below we're going to
- // define functions that can be activated
- // with button presses, corresponding to
- // each of the four Graffiti primitives.
+ window.Unsubscribe = async function() {
+ await graffiti.unsubscribe(myTag)
+ displayObjects()
+ }
// Create an object containing a special string
- const special = crypto.randomUUID()
- const usedIDs = []
window.Update = async function() {
- usedIDs.unshift(crypto.randomUUID())
- await graffiti.update({
- _id: usedIDs[0],
- _by: graffiti.myID,
- special
- }, {})
+ console.log(await graffiti.update(
+ graffiti.completeObject({_tags: [myTag]})))
+ displayObjects()
}
// Remove an existing object
window.Remove = async function() {
- if ( usedIDs.length ) {
- await graffiti.remove( usedIDs.pop() )
- }
+ const objects = graffiti.objectsByTags(myTag)
+ console.log(await graffiti.remove(objects[0]._key))
+ displayObjects()
}
- // Subscribe to objects containing the special string
- let queryID = null
- window.Subscribe = async function() {
- if (queryID) return
- count = 0
- queryID = await graffiti.subscribe(
- { special },
- (obj)=> { count++; displayCount() },
- (obj)=> { count--; displayCount() }
- )
- displayCount()
- }
-
- // Unsubscribe to the existing query
- window.Unsubscribe = async function() {
- if (queryID) {
- await graffiti.unsubscribe(queryID)
- queryID = null
- document.getElementById('status').innerHTML = "Unsubscribed"
- }
- }
</script>
</body>
</html>