add option to disable gc (compatible with older versions)

This commit is contained in:
Kevin Jahns 2018-05-02 18:42:18 +02:00
parent bc32f7348e
commit bdb3782f8f
3 changed files with 5 additions and 4 deletions

View File

@ -25,7 +25,7 @@ function _integrateRemoteStructHelper (y, struct) {
if (y.ss.getState(id.user) > id.clock) { if (y.ss.getState(id.user) > id.clock) {
return return
} }
if (struct.constructor === GC || (struct._parent.constructor !== GC && struct._parent._deleted === false)) { if (!y.gcEnabled || struct.constructor === GC || (struct._parent.constructor !== GC && struct._parent._deleted === false)) {
// Is either a GC or Item with an undeleted parent // Is either a GC or Item with an undeleted parent
// save to integrate // save to integrate
struct._integrate(y) struct._integrate(y)

View File

@ -217,8 +217,8 @@ export default class Type extends Item {
* collect the children of this type. * collect the children of this type.
*/ */
_delete (y, createDelete, gcChildren) { _delete (y, createDelete, gcChildren) {
if (gcChildren === undefined) { if (gcChildren === undefined || !y.gcEnabled) {
gcChildren = y._hasUndoManager === false gcChildren = y._hasUndoManager === false && y.gcEnabled
} }
super._delete(y, createDelete, gcChildren) super._delete(y, createDelete, gcChildren)
y._transaction.changedTypes.delete(this) y._transaction.changedTypes.delete(this)

View File

@ -28,8 +28,9 @@ export { default as DomBinding } from './Bindings/DomBinding/DomBinding.js'
* @param {AbstractPersistence} persistence Persistence adapter instance * @param {AbstractPersistence} persistence Persistence adapter instance
*/ */
export default class Y extends NamedEventHandler { export default class Y extends NamedEventHandler {
constructor (room, opts, persistence) { constructor (room, opts, persistence, conf = {}) {
super() super()
this.gcEnabled = conf.gc || false
/** /**
* The room name that this Yjs instance connects to. * The room name that this Yjs instance connects to.
* @type {String} * @type {String}