Browse Source

avoid creating unneccessary visual props objects

Alexander Rose 4 năm trước cách đây
mục cha
commit
769022e88c
2 tập tin đã thay đổi với 6 bổ sung6 xóa
  1. 4 4
      src/mol-repr/structure/units-visual.ts
  2. 2 2
      src/mol-repr/visual.ts

+ 4 - 4
src/mol-repr/structure/units-visual.ts

@@ -81,12 +81,12 @@ export function UnitsVisual<G extends Geometry, P extends StructureParams & Geom
     let geometry: G;
     let locationIt: LocationIterator;
 
-    function prepareUpdate(theme: Theme, props: Partial<PD.Values<P>> = {}, structureGroup: StructureGroup) {
+    function prepareUpdate(theme: Theme, props: PD.Values<P>, structureGroup: StructureGroup) {
         if (!structureGroup && !currentStructureGroup) {
             throw new Error('missing structureGroup');
         }
 
-        newProps = Object.assign({}, currentProps, props);
+        newProps = props;
         newTheme = theme;
         newStructureGroup = structureGroup;
 
@@ -130,7 +130,7 @@ export function UnitsVisual<G extends Geometry, P extends StructureParams & Geom
         if (Unit.conformationId(newUnit) !== Unit.conformationId(currentUnit)) {
             // console.log('new conformation');
             updateState.updateTransform = true;
-            if (!Unit.areAreConformationsEquivalent(newUnit, currentUnit)) {
+            if (!updateState.createGeometry && !Unit.areAreConformationsEquivalent(newUnit, currentUnit)) {
                 // console.log('new position');
                 updateState.createGeometry = true;
             }
@@ -236,7 +236,7 @@ export function UnitsVisual<G extends Geometry, P extends StructureParams & Geom
     return {
         get groupCount() { return locationIt ? locationIt.count : 0; },
         get renderObject () { return locationIt && locationIt.count ? renderObject : undefined; },
-        createOrUpdate(ctx: VisualContext, theme: Theme, props: Partial<PD.Values<P>> = {}, structureGroup?: StructureGroup) {
+        createOrUpdate(ctx: VisualContext, theme: Theme, props: PD.Values<P>, structureGroup?: StructureGroup) {
             prepareUpdate(theme, props, structureGroup || currentStructureGroup);
             if (updateState.createGeometry) {
                 const newGeometry = _createGeometry(ctx, newStructureGroup.group.units[0], newStructureGroup.structure, newTheme, newProps, geometry);

+ 2 - 2
src/mol-repr/visual.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -35,7 +35,7 @@ interface Visual<D, P extends PD.Params> {
     /** Number of addressable groups in all instances of the visual */
     readonly groupCount: number
     readonly renderObject: GraphicsRenderObject | undefined
-    createOrUpdate: (ctx: VisualContext, theme: Theme, props?: Partial<PD.Values<P>>, data?: D) => Promise<void> | void
+    createOrUpdate: (ctx: VisualContext, theme: Theme, props: PD.Values<P>, data?: D) => Promise<void> | void
     getLoci: (pickingId: PickingId) => Loci
     mark: (loci: Loci, action: MarkerAction) => boolean
     setVisibility: (visible: boolean) => void