diff --git a/examples/browser/browser.html b/examples/browser/browser.html
index c61e5b5..370f4e9 100644
--- a/examples/browser/browser.html
+++ b/examples/browser/browser.html
@@ -29,16 +29,17 @@
const query = () => {
const startTime = new Date().getTime()
const idx = Math.floor(Math.random() * creatures.length)
+ const creature = creatures[idx] + " " + creatures[idx]
// Set a key-value pair
- db.put(key, "db.put #" + count + " - GrEEtinGs to " + creatures[idx])
+ db.put(key, "db.put #" + count + " - GrEEtinGs to " + creature)
.then((res) => {
const endTime = new Date().getTime()
console.log(`db.put (#${count}) took ${(endTime - startTime)} ms\n`)
count ++
})
.then(() => counter.inc()) // Increase the counter by one
- .then(() => log.add(creatures[idx])) // Add an event to 'latest visitors' log
+ .then(() => log.add(creature)) // Add an event to 'latest visitors' log
.then(() => {
const result = db.get(key)
const latest = log.iterator({ limit: 5 }).collect()
@@ -70,7 +71,9 @@
console.error(e.stack)
})
}
- setInterval(query, Math.random() * 3 * 1000)
+
+ // Start query loop when the databse has loaded its history
+ db.events.on('ready', () => setInterval(query, 1000))
} catch(e) {
console.error(e.stack)
diff --git a/examples/browser/index.js b/examples/browser/index.js
index 4574684..f4a38b6 100644
--- a/examples/browser/index.js
+++ b/examples/browser/index.js
@@ -1,6 +1,6 @@
'use strict'
-const IpfsApi = require('exports?IpfsApi!ipfs-api/dist/index.js')
+const IpfsApi = require('exports-loader?IpfsApi!ipfs-api/dist/index.js')
const OrbitDB = require('../../src/OrbitDB')
const username = new Date().getTime()
@@ -63,7 +63,9 @@ Visitor Count: ${count}
console.error(e.stack)
})
}
- setInterval(query, Math.random() * 3 * 1000)
+
+ // Start query loop when the databse has loaded its history
+ db.events.on('ready', () => setInterval(query, 1000))
} catch(e) {
console.error(e.stack)