fixed several consistency issues with y-indexeddb. Implemented support for .close() - a soft replacement for .destroy()

This commit is contained in:
Kevin Jahns 2016-10-31 01:17:24 +01:00
parent 8ab16f4ada
commit f32ff1b613
5 changed files with 40 additions and 18 deletions

View File

@ -198,12 +198,16 @@ The promise returns an instance of Y. We denote it with a lower case `y`.
* Force to disconnect this instance from the other instances
* y.connector.reconnect()
* Try to reconnect to the other instances (needs to be supported by the connector)
* Not supported by y-xmpp
* y.destroy()
* Not supported by y-xmpp
* y.close()
* Destroy this object.
* Destroys all types (they will throw weird errors if you still use them)
* Disconnects from the other instances (via connector)
* Returns a promise
* y.destroy()
* calls y.close()
* Removes all data from the database
* Returns a promise
* y.db.stopGarbageCollector()
* Stop the garbage collector. Call y.db.garbageCollect() to continue garbage collection
* y.db.gcTimeout :: Number (defaults to 50000 ms)

View File

@ -239,10 +239,7 @@ module.exports = function (Y /* :any */) {
this.gc2 = this.gc2.filter(filter)
delete op.gc
}
* destroy () {
clearInterval(this.gcInterval)
this.gcInterval = null
this.stopRepairCheck()
destroyTypes () {
for (var key in this.initializedTypes) {
var type = this.initializedTypes[key]
if (type._destroy != null) {
@ -252,6 +249,11 @@ module.exports = function (Y /* :any */) {
}
}
}
* destroy () {
clearInterval(this.gcInterval)
this.gcInterval = null
this.stopRepairCheck()
}
setUserId (userId) {
if (!this.userIdPromise.inProgress) {
this.userIdPromise.inProgress = true
@ -434,8 +436,7 @@ module.exports = function (Y /* :any */) {
*/
* operationAdded (transaction, op) {
if (op.struct === 'Delete') {
var target = yield* transaction.getInsertion(op.target)
var type = this.initializedTypes[JSON.stringify(target.parent)]
var type = this.initializedTypes[JSON.stringify(op.targetParent)]
if (type != null) {
yield* type._changed(transaction, op)
}
@ -503,10 +504,8 @@ module.exports = function (Y /* :any */) {
resolve: resolve,
promise: promise
}
return promise
} else {
return this.transactionsFinished.promise
}
return this.transactionsFinished.promise
} else {
return Promise.resolve()
}

View File

@ -30,7 +30,11 @@ module.exports = function (Y/* :any */) {
*/
Delete: {
encode: function (op) {
return op
return {
target: op.target,
length: op.length || 0,
struct: 'Delete'
}
},
requiredOps: function (op) {
return [] // [op.target]

View File

@ -206,7 +206,8 @@ module.exports = function (Y/* :any */) {
yield* this.store.operationAdded(this, {
struct: 'Delete',
target: target.id,
length: targetLength
length: targetLength,
targetParent: target.parent
})
}
// need to gc in the end!

View File

@ -190,16 +190,30 @@ class YConfig {
return this.connector.reconnect()
}
destroy () {
var self = this
return this.close().then(function () {
if (self.db.deleteDB != null) {
return self.db.deleteDB()
} else {
return Promise.resolve()
}
})
}
close () {
var self = this
this.share = null
if (this.connector.destroy != null) {
this.connector.destroy()
} else {
this.connector.disconnect()
}
var self = this
this.db.requestTransaction(function * () {
yield* self.db.destroy()
self.connector = null
self.db = null
return this.db.whenTransactionsFinished(function () {
this.db.destroyTypes()
// make sure to wait for all transactions before destroying the db
this.db.requestTransaction(function * () {
yield* self.db.destroy()
})
return this.db.whenTransactionsFinished()
})
}
}