From c7259a8f6ed1427b168845bacb8526d4656ae4d6 Mon Sep 17 00:00:00 2001
From: Moritz Langenstein <ml5717@ic.ac.uk>
Date: Fri, 15 Nov 2019 01:34:53 +0000
Subject: [PATCH] (ml5717) yjs insert performance improvement

---
 src/y-union.js | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/y-union.js b/src/y-union.js
index 78a8762..aabe816 100644
--- a/src/y-union.js
+++ b/src/y-union.js
@@ -6,7 +6,7 @@ export const Union = {
   create: function(id) {
     return {
       id: id,
-      union: -1,
+      union: null,
       struct: "Union",
     }
   },
@@ -15,7 +15,7 @@ export const Union = {
       struct: "Union",
       type: op.type,
       id: op.id,
-      union: -1,
+      union: null,
     }
     if (op.requires != null) {
       e.requires = op.requires
@@ -39,7 +39,7 @@ export default function extendYUnion(Y) {
       this._parent = null
       this._deepEventHandler = new Y.utils.EventListenerHandler()
       this.os = os
-      this.union = Y.utils.copyObject(model.union)
+      this.union = model.union ? Y.utils.copyObject(model.union) : null
       this.contents = contents
       this.eventHandler = new Y.utils.EventHandler((op) => {
         // compute op event
@@ -96,7 +96,7 @@ export default function extendYUnion(Y) {
       const insert = {
         id: this.os.getNextOpId(1),
         left: null,
-        right: null,
+        right: this.union,
         origin: null,
         parent: this._model,
         content: [mergedContents],
@@ -139,7 +139,7 @@ export default function extendYUnion(Y) {
       initType: function* YUnionInitializer(os, model) {
         const union = model.union
         const contents =
-          union != -1 ? yield* this.getOperation(union).content[0] : "[]"
+          union !== null ? yield* this.getOperation(union).content[0] : "[]"
         return new YUnion(os, model, contents)
       },
       createType: function YUnionCreator(os, model) {
-- 
GitLab