Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aphelionz committed May 11, 2020
1 parent 5686a3d commit 7adb894
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 82 deletions.
6 changes: 3 additions & 3 deletions dist/orbit-db-store.min.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions src/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ class Store {
} catch (e) {
console.error('Store Error:', e)
}
this.events.on("replicated.progress", (address, hash, entry, progress, have) => {
this._procEntry(entry);
});
this.events.on("write", (address, entry, heads) => {
this._procEntry(entry);
});
this.events.on('replicated.progress', (address, hash, entry, progress, have) => {
this._procEntry(entry)
})
this.events.on('write', (address, entry, heads) => {
this._procEntry(entry)
})
}

get all () {
Expand Down Expand Up @@ -194,8 +194,8 @@ class Store {
}

// Remove all event listeners
for(var event in this.events._events) {
this.events.removeAllListeners(event);
for (var event in this.events._events) {
this.events.removeAllListeners(event)
}

// Database is now closed
Expand Down Expand Up @@ -529,14 +529,14 @@ class Store {
_addOperationBatch (data, batchOperation, lastOperation, onProgressCallback) {
throw new Error('Not implemented!')
}
_procEntry(entry) {
var { payload, hash } = entry;
var { op } = payload;
if(op) {
this.events.emit(`log.op.${op}`, this.address.toString(), hash, payload);

_procEntry (entry) {
var { payload, hash } = entry
var { op } = payload
if (op) {
this.events.emit(`log.op.${op}`, this.address.toString(), hash, payload)
} else {
this.events.emit(`log.op.none`, this.address.toString(), hash, payload);
this.events.emit('log.op.none', this.address.toString(), hash, payload)
}
this.events.emit('log.op', op, this.address.toString(), hash, payload)
}
Expand Down
103 changes: 52 additions & 51 deletions test/events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,68 @@ const DefaultOptions = Store.DefaultOptions

// Test utils
const {
config,
testAPIs,
startIpfs,
stopIpfs,
implementations
config,
testAPIs,
startIpfs,
stopIpfs,
implementations
} = require('orbit-db-test-utils')

const properLevelModule = implementations.filter(i => i.key.indexOf('memdown') > -1).map(i => i.module)[0]
const storage = require('orbit-db-storage-adapter')(properLevelModule)

Object.keys(testAPIs).forEach((IPFS) => {
describe(`Events ${IPFS}`, function () {
let ipfs, testIdentity, identityStore, store, cacheStore
describe(`Events ${IPFS}`, function () {
let ipfsd, ipfs, testIdentity, identityStore, store, cacheStore

this.timeout(config.timeout)
this.timeout(config.timeout)

const ipfsConfig = Object.assign({}, config.defaultIpfsConfig, {
repo: config.defaultIpfsConfig.repo + '-entry' + new Date().getTime()
})
after(async () => {
await store.close()
await stopIpfs(ipfs)
await identityStore.close()
await cacheStore.close()
})
const ipfsConfig = Object.assign({}, config.defaultIpfsConfig, {
repo: config.defaultIpfsConfig.repo + '-entry' + new Date().getTime()
})
after(async () => {
await store.close()
await stopIpfs(ipfsd)
await identityStore.close()
await cacheStore.close()
})

afterEach(async () => {
await store.drop()
await cacheStore.open()
await identityStore.open()
})
before(async () => {
identityStore = await storage.createStore('identity')
const keystore = new Keystore(identityStore)
afterEach(async () => {
await store.drop()
await cacheStore.open()
await identityStore.open()
})

cacheStore = await storage.createStore('cache')
const cache = new Cache(cacheStore)
before(async () => {
identityStore = await storage.createStore('identity')
const keystore = new Keystore(identityStore)

testIdentity = await IdentityProvider.createIdentity({ id: 'userA', keystore })
ipfs = await startIpfs(IPFS, ipfsConfig)
cacheStore = await storage.createStore('cache')
const cache = new Cache(cacheStore)

const address = 'test-address'
const options = Object.assign({}, DefaultOptions, { cache })
store = new Store(ipfs, testIdentity, address, options)
})
it('Specific log.op event', (done) => {
var data = {
op: "SET",
key: "transaction",
value: "data"
}
store.events.on("log.op.SET", (id, address, payload) => {
var {op, key, value} = payload;
assert.strictEqual(op, data.op);
assert.strictEqual(key, data.key);
assert.strictEqual(value, data.value);
assert.strictEqual(id, 'test-address');
done();
})
store._addOperation(data)

})
testIdentity = await IdentityProvider.createIdentity({ id: 'userA', keystore })
ipfsd = await startIpfs(IPFS, ipfsConfig)
ipfs = ipfsd.api

const address = 'test-address'
const options = Object.assign({}, DefaultOptions, { cache })
store = new Store(ipfs, testIdentity, address, options)
})
it('Specific log.op event', (done) => {
var data = {
op: 'SET',
key: 'transaction',
value: 'data'
}
store.events.on('log.op.SET', (id, address, payload) => {
var { op, key, value } = payload
assert.strictEqual(op, data.op)
assert.strictEqual(key, data.key)
assert.strictEqual(value, data.value)
assert.strictEqual(id, 'test-address')
done()
})
store._addOperation(data)
})
})
})
})

0 comments on commit 7adb894

Please sign in to comment.