From 73c28952c2aeb510e787bbab46f48fe473ec4240 Mon Sep 17 00:00:00 2001
From: Kevin Jahns <kevin.jahns@protonmail.com>
Date: Sat, 30 Mar 2019 11:00:54 +0100
Subject: [PATCH] fix all types but yxmlelement

---
 src/types/YArray.js    | 27 ++-------------------------
 src/types/YXmlEvent.js |  4 ++--
 src/types/YXmlText.js  | 23 ++++++-----------------
 3 files changed, 10 insertions(+), 44 deletions(-)

diff --git a/src/types/YArray.js b/src/types/YArray.js
index 658afd27..a011efe4 100644
--- a/src/types/YArray.js
+++ b/src/types/YArray.js
@@ -4,11 +4,9 @@
 
 import { AbstractItem } from '../structs/AbstractItem.js' // eslint-disable-line
 import { ItemType } from '../structs/ItemType.js' // eslint-disable-line
-import { AbstractType, typeArrayGet, typeArrayToArray, typeArrayForEach, typeArrayCreateIterator, typeArrayInsertGenerics } from './AbstractType.js'
+import { AbstractType, typeArrayGet, typeArrayToArray, typeArrayForEach, typeArrayCreateIterator, typeArrayInsertGenerics, typeArrayDelete } from './AbstractType.js'
 import { YEvent } from '../utils/YEvent.js'
 import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
-import { getItemCleanStart, getItemCleanEnd } from '../utils/StructStore.js'
-import { createID } from '../utils/ID.js'
 import * as decoding from 'lib0/decoding.js' // eslint-disable-line
 
 /**
@@ -180,28 +178,7 @@ export class YArray extends AbstractType {
   delete (index, length = 1) {
     if (this._y !== null) {
       this._y.transact(transaction => {
-        const store = transaction.y.store
-        let item = this._start
-        let count = 0
-        while (item !== null && length > 0) {
-          if (!item.deleted && item.countable) {
-            if (count <= index && index < count + item.length) {
-              const diffDel = index - count
-              if (diffDel > 0) {
-                item = getItemCleanStart(store, transaction, createID(item.id.client, item.id.clock + diffDel))
-              }
-              if (length < item.length) {
-                getItemCleanEnd(store, transaction, createID(item.id.client, item.id.clock + length))
-              }
-              length -= item.length
-              item.delete(transaction)
-              count += diffDel
-            } else {
-              count += item.length
-            }
-          }
-          item = item.right
-        }
+        typeArrayDelete(transaction, this, index, length)
       })
     } else {
       // @ts-ignore _prelimContent is defined because this is not yet integrated
diff --git a/src/types/YXmlEvent.js b/src/types/YXmlEvent.js
index dc109694..d73ed4d4 100644
--- a/src/types/YXmlEvent.js
+++ b/src/types/YXmlEvent.js
@@ -4,7 +4,7 @@
 
 import { YEvent } from '../utils/YEvent.js'
 
-import { Type } from './AbstractType.js' // eslint-disable-line
+import { AbstractType } from './AbstractType.js' // eslint-disable-line
 import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
 
 /**
@@ -14,7 +14,7 @@ import { Transaction } from '../utils/Transaction.js' // eslint-disable-line
  */
 export class YXmlEvent extends YEvent {
   /**
-   * @param {Type} target The target on which the event is created.
+   * @param {AbstractType} target The target on which the event is created.
    * @param {Set<string|null>} subs The set of changed attributes. `null` is included if the
    *                   child list changed.
    * @param {Boolean} remote Whether this change was created by a remote peer.
diff --git a/src/types/YXmlText.js b/src/types/YXmlText.js
index 58f87f79..69aeb10a 100644
--- a/src/types/YXmlText.js
+++ b/src/types/YXmlText.js
@@ -3,7 +3,7 @@
  */
 
 import { YText } from './YText.js'
-import { Y } from '../utils/Y.js' // eslint-disable-line
+import * as decoding from 'lib0/decoding.js' // eslint-disable-line
 
 /**
  * Represents text in a Dom Element. In the future this type will also handle
@@ -18,7 +18,7 @@ export class YXmlText extends YText {
    *                                        nodejs)
    * @param {Object<string, any>} [hooks] Optional property to customize how hooks
    *                                             are presented in the DOM
-   * @param {DomBinding} [binding] You should not set this property. This is
+   * @param {any} [binding] You should not set this property. This is
    *                               used if DomBinding wants to create a
    *                               association to the created DOM type.
    * @return {Text} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}
@@ -32,21 +32,10 @@ export class YXmlText extends YText {
     }
     return dom
   }
-
-  /**
-   * Mark this Item as deleted.
-   *
-   * @param {Y} y The Yjs instance
-   * @param {boolean} createDelete Whether to propagate a message that this
-   *                               Type was deleted.
-   * @param {boolean} [gcChildren=y._hasUndoManager===false] Whether to garbage
-   *                                         collect the children of this type.
-   *
-   * @private
-   */
-  _delete (y, createDelete, gcChildren) {
-    super._delete(y, createDelete, gcChildren)
-  }
 }
 
+/**
+ * @param {decoding.Decoder} decoder
+ * @return {YXmlText}
+ */
 export const readYXmlText = decoder => new YXmlText()