From 6d4d11407d4442f5b63f918ab7c3ed29238618c3 Mon Sep 17 00:00:00 2001
From: Andrey Platov <andrey@hardcoreeng.com>
Date: Mon, 9 Aug 2021 08:59:50 +0200
Subject: [PATCH] clean client

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
---
 packages/core/src/client.ts | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts
index 417ec46652..4d296d0e98 100644
--- a/packages/core/src/client.ts
+++ b/packages/core/src/client.ts
@@ -63,6 +63,14 @@ class ClientImpl implements Client {
     await Promise.all([this.conn.tx(tx), this.model.tx(tx)])
     this.notify?.(tx)
   }
+
+  async updateFromRemote (tx: Tx): Promise<void> {
+    if (tx.objectSpace === core.space.Model) {
+      this.hierarchy.tx(tx)
+      await this.model.tx(tx)
+    }
+    this.notify?.(tx)
+  }
 }
 
 /**
@@ -71,7 +79,7 @@ class ClientImpl implements Client {
 export async function createClient (
   connect: (txHandler: TxHander) => Promise<Storage>
 ): Promise<Client> {
-  let client: Client | null = null
+  let client: ClientImpl | null = null
   let txBuffer: Tx[] | undefined = []
 
   const hierarchy = new Hierarchy()
@@ -81,8 +89,8 @@ export async function createClient (
     if (client === null) {
       txBuffer?.push(tx)
     } else {
-      console.log('handler got ', tx)
-      client.notify?.(tx)
+      // eslint-disable-next-line @typescript-eslint/no-floating-promises
+      client.updateFromRemote(tx)
     }
   }