From 63d1a3421965d3b24c8606ebd11708ca1a0862b5 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Thu, 5 Apr 2018 18:25:26 +0200
Subject: [PATCH] Added id field to ValueBox

---
 src/mol-util/value-cell.ts | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/mol-util/value-cell.ts b/src/mol-util/value-cell.ts
index 762bcbf7e..ef5a0a338 100644
--- a/src/mol-util/value-cell.ts
+++ b/src/mol-util/value-cell.ts
@@ -9,15 +9,25 @@ interface ValueCell<T> { value: T }
 /** Create a mutable value cell. */
 function ValueCell<T>(value: T): ValueCell<T> { return { value }; }
 
+let _valueBoxId = 0;
+function getNextId() {
+    return _valueBoxId++ % 0x7FFFFFFF;
+}
+
 /** An immutable value box that also holds a version of the attribute. */
-interface ValueBox<T> { readonly version: number, readonly value: T }
+interface ValueBox<T> {
+    // Unique identifier in the range 0 to 0x7FFFFFFF
+    readonly id: number,
+    readonly version: number,
+    readonly value: T
+}
 /** Create a new box with the specified value and version = 0 */
 function ValueBox<T>(value: T): ValueBox<T>
 /** Create a new box by updating the value of an old box and incrementing the version number. */
 function ValueBox<T>(box: ValueBox<T>, value: T): ValueBox<T>
 function ValueBox<T>(boxOrValue: T | ValueBox<T>, value?: T): ValueBox<T> {
-    if (arguments.length === 2) return { version: (boxOrValue as ValueBox<T>).version + 1, value: value! };
-    return { version: 0, value: boxOrValue as T };
+    if (arguments.length === 2) return { id: (boxOrValue as ValueBox<T>).id, version: (boxOrValue as ValueBox<T>).version + 1, value: value! };
+    return { id: getNextId(), version: 0, value: boxOrValue as T };
 }
 
 export { ValueCell, ValueBox };
-- 
GitLab