Explorar o código

fix circular import issue

Alexander Rose %!s(int64=6) %!d(string=hai) anos
pai
achega
c15a1bff77
Modificáronse 1 ficheiros con 6 adicións e 2 borrados
  1. 6 2
      src/mol-view/label.ts

+ 6 - 2
src/mol-view/label.ts

@@ -9,8 +9,9 @@ import { Unit, StructureElement, StructureProperties as Props } from 'mol-model/
 import { Loci } from 'mol-model/loci';
 import { OrderedSet } from 'mol-data/int';
 
-const elementLocA = StructureElement.create()
-const elementLocB = StructureElement.create()
+// for `labelFirst`, don't create right away to avaiod problems with circular dependencies/imports
+let elementLocA: StructureElement
+let elementLocB: StructureElement
 
 function setElementLocation(loc: StructureElement, unit: Unit, index: StructureElement.UnitIndex) {
     loc.unit = unit
@@ -18,6 +19,9 @@ function setElementLocation(loc: StructureElement, unit: Unit, index: StructureE
 }
 
 export function labelFirst(loci: Loci): string {
+    if (!elementLocA) elementLocA = StructureElement.create()
+    if (!elementLocB) elementLocB = StructureElement.create()
+
     switch (loci.kind) {
         case 'element-loci':
             const e = loci.elements[0]