fixed several consistency issues with y-indexeddb. Implemented support for .close() - a soft replacement for .destroy()
This commit is contained in:
parent
8ab16f4ada
commit
f32ff1b613
@ -199,11 +199,15 @@ The promise returns an instance of Y. We denote it with a lower case `y`.
|
|||||||
* y.connector.reconnect()
|
* y.connector.reconnect()
|
||||||
* Try to reconnect to the other instances (needs to be supported by the connector)
|
* Try to reconnect to the other instances (needs to be supported by the connector)
|
||||||
* Not supported by y-xmpp
|
* Not supported by y-xmpp
|
||||||
* y.destroy()
|
* y.close()
|
||||||
* Destroy this object.
|
* Destroy this object.
|
||||||
* Destroys all types (they will throw weird errors if you still use them)
|
* Destroys all types (they will throw weird errors if you still use them)
|
||||||
* Disconnects from the other instances (via connector)
|
* Disconnects from the other instances (via connector)
|
||||||
|
* Returns a promise
|
||||||
|
* y.destroy()
|
||||||
|
* calls y.close()
|
||||||
* Removes all data from the database
|
* Removes all data from the database
|
||||||
|
* Returns a promise
|
||||||
* y.db.stopGarbageCollector()
|
* y.db.stopGarbageCollector()
|
||||||
* Stop the garbage collector. Call y.db.garbageCollect() to continue garbage collection
|
* Stop the garbage collector. Call y.db.garbageCollect() to continue garbage collection
|
||||||
* y.db.gcTimeout :: Number (defaults to 50000 ms)
|
* y.db.gcTimeout :: Number (defaults to 50000 ms)
|
||||||
|
@ -239,10 +239,7 @@ module.exports = function (Y /* :any */) {
|
|||||||
this.gc2 = this.gc2.filter(filter)
|
this.gc2 = this.gc2.filter(filter)
|
||||||
delete op.gc
|
delete op.gc
|
||||||
}
|
}
|
||||||
* destroy () {
|
destroyTypes () {
|
||||||
clearInterval(this.gcInterval)
|
|
||||||
this.gcInterval = null
|
|
||||||
this.stopRepairCheck()
|
|
||||||
for (var key in this.initializedTypes) {
|
for (var key in this.initializedTypes) {
|
||||||
var type = this.initializedTypes[key]
|
var type = this.initializedTypes[key]
|
||||||
if (type._destroy != null) {
|
if (type._destroy != null) {
|
||||||
@ -252,6 +249,11 @@ module.exports = function (Y /* :any */) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
* destroy () {
|
||||||
|
clearInterval(this.gcInterval)
|
||||||
|
this.gcInterval = null
|
||||||
|
this.stopRepairCheck()
|
||||||
|
}
|
||||||
setUserId (userId) {
|
setUserId (userId) {
|
||||||
if (!this.userIdPromise.inProgress) {
|
if (!this.userIdPromise.inProgress) {
|
||||||
this.userIdPromise.inProgress = true
|
this.userIdPromise.inProgress = true
|
||||||
@ -434,8 +436,7 @@ module.exports = function (Y /* :any */) {
|
|||||||
*/
|
*/
|
||||||
* operationAdded (transaction, op) {
|
* operationAdded (transaction, op) {
|
||||||
if (op.struct === 'Delete') {
|
if (op.struct === 'Delete') {
|
||||||
var target = yield* transaction.getInsertion(op.target)
|
var type = this.initializedTypes[JSON.stringify(op.targetParent)]
|
||||||
var type = this.initializedTypes[JSON.stringify(target.parent)]
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
yield* type._changed(transaction, op)
|
yield* type._changed(transaction, op)
|
||||||
}
|
}
|
||||||
@ -503,10 +504,8 @@ module.exports = function (Y /* :any */) {
|
|||||||
resolve: resolve,
|
resolve: resolve,
|
||||||
promise: promise
|
promise: promise
|
||||||
}
|
}
|
||||||
return promise
|
|
||||||
} else {
|
|
||||||
return this.transactionsFinished.promise
|
|
||||||
}
|
}
|
||||||
|
return this.transactionsFinished.promise
|
||||||
} else {
|
} else {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,11 @@ module.exports = function (Y/* :any */) {
|
|||||||
*/
|
*/
|
||||||
Delete: {
|
Delete: {
|
||||||
encode: function (op) {
|
encode: function (op) {
|
||||||
return op
|
return {
|
||||||
|
target: op.target,
|
||||||
|
length: op.length || 0,
|
||||||
|
struct: 'Delete'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
requiredOps: function (op) {
|
requiredOps: function (op) {
|
||||||
return [] // [op.target]
|
return [] // [op.target]
|
||||||
|
@ -206,7 +206,8 @@ module.exports = function (Y/* :any */) {
|
|||||||
yield* this.store.operationAdded(this, {
|
yield* this.store.operationAdded(this, {
|
||||||
struct: 'Delete',
|
struct: 'Delete',
|
||||||
target: target.id,
|
target: target.id,
|
||||||
length: targetLength
|
length: targetLength,
|
||||||
|
targetParent: target.parent
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// need to gc in the end!
|
// need to gc in the end!
|
||||||
|
24
src/y.js
24
src/y.js
@ -190,16 +190,30 @@ class YConfig {
|
|||||||
return this.connector.reconnect()
|
return this.connector.reconnect()
|
||||||
}
|
}
|
||||||
destroy () {
|
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) {
|
if (this.connector.destroy != null) {
|
||||||
this.connector.destroy()
|
this.connector.destroy()
|
||||||
} else {
|
} else {
|
||||||
this.connector.disconnect()
|
this.connector.disconnect()
|
||||||
}
|
}
|
||||||
var self = this
|
return this.db.whenTransactionsFinished(function () {
|
||||||
this.db.requestTransaction(function * () {
|
this.db.destroyTypes()
|
||||||
yield* self.db.destroy()
|
// make sure to wait for all transactions before destroying the db
|
||||||
self.connector = null
|
this.db.requestTransaction(function * () {
|
||||||
self.db = null
|
yield* self.db.destroy()
|
||||||
|
})
|
||||||
|
return this.db.whenTransactionsFinished()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user