Fix browser examples

This commit is contained in:
haad 2016-11-25 16:02:49 +01:00
parent c636bbfd00
commit 6e316502c6
5 changed files with 75 additions and 85 deletions

View File

@ -13,45 +13,44 @@ module.exports = {
Buffer: true
},
plugins: [
// new webpack.optimize.UglifyJsPlugin({
// mangle: false,
// compress: { warnings: false }
// })
new webpack.optimize.UglifyJsPlugin({
mangle: false,
compress: { warnings: false }
})
],
resolve: {
modules: [
path.join(__dirname, '../node_modules')
]
'node_modules',
path.resolve(__dirname, '../node_modules')
],
alias: {
// These are needed because node-libs-browser depends on outdated
// versions
//
// Can be dropped once https://github.com/devongovett/browserify-zlib/pull/18
// is shipped
zlib: 'browserify-zlib',
// Can be dropped once https://github.com/webpack/node-libs-browser/pull/41
// is shipped
http: 'stream-http'
}
},
resolveLoader: {
modules: [
'node_modules',
path.resolve(__dirname, '../node_modules')
],
moduleExtensions: ['-loader']
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: require.resolve('babel-preset-es2015'),
plugins: require.resolve('babel-plugin-transform-runtime')
}
},
{
test: /\.js$/,
include: /node_modules\/(hoek|qs|wreck|boom|ipfs.+|orbit.+|logplease|crdts|promisify-es|whatwg-fetch|node-fetch|isomorphic-fetch|db\.js)/,
loader: 'babel-loader',
query: {
presets: require.resolve('babel-preset-es2015'),
plugins: require.resolve('babel-plugin-transform-runtime')
}
},
{
test: /\.json$/,
loader: 'json-loader'
}
]
rules: [{
test: /\.json$/,
loader: 'json-loader'
}]
},
externals: {
net: '{}',
tls: '{}',
'require-dir': '{}'
}
node: {
Buffer: true
},
plugins: [],
target: 'web'
}

View File

@ -11,16 +11,18 @@ let lastTenSeconds = 0
// Main loop
const queryLoop = (db) => {
db.add(totalQueries).then(() => {
totalQueries ++
lastTenSeconds ++
queriesPerSecond ++
process.nextTick(() => queryLoop(db))
})
db.add(totalQueries)
.then(() => {
totalQueries ++
lastTenSeconds ++
queriesPerSecond ++
process.nextTick(() => queryLoop(db))
})
.catch((e) => console.error(e))
}
// Start
console.log("Starting...")
console.log("Starting IPFS daemon...")
const ipfs = new IpfsDaemon({ IpfsDataDir: '/tmp/orbit-db-benchmark' })

View File

@ -1,6 +1,6 @@
'use strict'
const IpfsApi = require('exports-loader?HaadIpfsApi!@haad/ipfs-api/dist/index.js')
const IpfsApi = require('@haad/ipfs-api')
const OrbitDB = require('../../src/OrbitDB')
const username = new Date().getTime()
@ -9,7 +9,7 @@ const key = 'greeting'
try {
const elm = document.getElementById("result")
const ipfs = IpfsApi('localhost', '5001')
const ipfs = new IpfsApi('localhost', '5001')
const orbit = new OrbitDB(ipfs, username)
const db = orbit.kvstore(channel)

View File

@ -4,6 +4,7 @@ const IpfsDaemon = require('ipfs-daemon')
const OrbitDB = require('../src/OrbitDB')
const userId = Math.floor(Math.random() * 1000)
const conf = {
IpfsDataDir: '/tmp/' + userId,
Addresses: {
@ -15,33 +16,35 @@ const conf = {
console.log("Starting...")
IpfsDaemon(conf)
.then((res) => {
const orbitdb = new OrbitDB(res.ipfs)
const db = orbitdb.kvstore("|orbit-db|examples|kvstore-example")
const ipfs = new IpfsDaemon(conf)
const creatures = ['🐙', '🐬', '🐋', '🐠', '🐡', '🦀', '🐢', '🐟', '🐳']
ipfs.on('error', (err) => console.error(err))
const query = () => {
const index = Math.floor(Math.random() * creatures.length)
db.put(userId, { avatar: creatures[index], updated: new Date().getTime() })
.then(() => {
const user = db.get(userId)
let output = `\n`
output += `----------------------\n`
output += `User\n`
output += `----------------------\n`
output += `Id: ${userId}\n`
output += `Avatar: ${user.avatar}\n`
output += `Updated: ${user.updated}\n`
output += `----------------------`
console.log(output)
})
.catch((e) => {
console.error(e.stack)
})
}
ipfs.on('ready', () => {
const orbitdb = new OrbitDB(ipfs, userId)
const db = orbitdb.kvstore("|orbit-db|examples|kvstore-example")
setInterval(query, 1000)
})
.catch((err) => console.error(err))
const creatures = ['🐙', '🐬', '🐋', '🐠', '🐡', '🦀', '🐢', '🐟', '🐳']
const query = () => {
const index = Math.floor(Math.random() * creatures.length)
db.put(userId, { avatar: creatures[index], updated: new Date().getTime() })
.then(() => {
const user = db.get(userId)
let output = `\n`
output += `----------------------\n`
output += `User\n`
output += `----------------------\n`
output += `Id: ${userId}\n`
output += `Avatar: ${user.avatar}\n`
output += `Updated: ${user.updated}\n`
output += `----------------------`
console.log(output)
})
.catch((e) => {
console.error(e.stack)
})
}
setInterval(query, 1000)
})

View File

@ -1,14 +0,0 @@
const IpfsDaemon = require('ipfs-daemon')
module.exports = IpfsDaemon({
IpfsDataDir: '/tmp/orbit-db-examples',
API: {
HTTPHeaders: {
"Access-Control-Allow-Origin": ['*'],
"Access-Control-Allow-Methods": ["PUT", "GET", "POST"],
"Access-Control-Allow-Credentials": ["true"]
}
}
})
.then((res) => console.log("Started IPFS daemon"))
.catch((err) => console.error(err))