From d00ccdb3d50a94bbb3d1c8cfb77ce213489ca1ad Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Fri, 16 Nov 2018 15:48:21 -0800 Subject: [PATCH] use Rx.Subject for repr.updated --- src/mol-repr/representation.ts | 11 ++++++----- src/mol-repr/shape/representation.ts | 7 ++++--- src/mol-repr/structure/complex-representation.ts | 7 ++++--- src/mol-repr/structure/units-representation.ts | 9 +++++---- src/mol-repr/volume/representation.ts | 7 ++++--- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/mol-repr/representation.ts b/src/mol-repr/representation.ts index cdd92dbcc..d271a2f35 100644 --- a/src/mol-repr/representation.ts +++ b/src/mol-repr/representation.ts @@ -15,7 +15,7 @@ import { getQualityProps } from './util'; import { ColorTheme } from 'mol-theme/color'; import { SizeTheme } from 'mol-theme/size'; import { Theme, ThemeRegistryContext } from 'mol-theme/theme'; -import { BehaviorSubject } from 'rxjs'; +import { Subject } from 'rxjs'; // export interface RepresentationProps { // visuals?: string[] @@ -80,7 +80,7 @@ export interface RepresentationContext { export { Representation } interface Representation<D, P extends PD.Params = {}> { readonly label: string - readonly updated: BehaviorSubject<number> + readonly updated: Subject<number> readonly renderObjects: ReadonlyArray<RenderObject> readonly props: Readonly<PD.Values<P>> readonly params: Readonly<P> @@ -94,7 +94,7 @@ interface Representation<D, P extends PD.Params = {}> { namespace Representation { export type Any = Representation<any> export const Empty: Any = { - label: '', renderObjects: [], props: {}, params: {}, updated: new BehaviorSubject(0), + label: '', renderObjects: [], props: {}, params: {}, updated: new Subject(), createOrUpdate: () => Task.constant('', undefined), getLoci: () => EmptyLoci, mark: () => false, @@ -106,7 +106,8 @@ namespace Representation { export type Def<D, P extends PD.Params = {}> = { [k: string]: (getParams: RepresentationParamsGetter<D, P>) => Representation<any, P> } export function createMulti<D, P extends PD.Params = {}>(label: string, getParams: RepresentationParamsGetter<D, P>, reprDefs: Def<D, P>): Representation<D, P> { - const updated = new BehaviorSubject(0) + let version = 0 + const updated = new Subject<number>() let currentParams: P let currentProps: PD.Values<P> @@ -155,7 +156,7 @@ namespace Representation { await reprList[i].createOrUpdate(ctx, currentProps, currentData).runInContext(runtime) } } - updated.next(updated.getValue() + 1) + updated.next(version++) }) }, getLoci: (pickingId: PickingId) => { diff --git a/src/mol-repr/shape/representation.ts b/src/mol-repr/shape/representation.ts index 87333b0e4..c8e7ac8db 100644 --- a/src/mol-repr/shape/representation.ts +++ b/src/mol-repr/shape/representation.ts @@ -19,7 +19,7 @@ import { PickingId } from 'mol-geo/geometry/picking'; import { MarkerAction, applyMarkerAction } from 'mol-geo/geometry/marker-data'; import { LocationIterator } from 'mol-geo/util/location-iterator'; import { createTheme } from 'mol-theme/theme'; -import { BehaviorSubject } from 'rxjs'; +import { Subject } from 'rxjs'; export interface ShapeRepresentation<P extends ShapeParams> extends Representation<Shape, P> { } @@ -31,7 +31,8 @@ export const ShapeParams = { export type ShapeParams = typeof ShapeParams export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentation<P> { - const updated = new BehaviorSubject(0) + let version = 0 + const updated = new Subject<number>() const renderObjects: RenderObject[] = [] let _renderObject: MeshRenderObject | undefined let _shape: Shape @@ -57,7 +58,7 @@ export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentatio _renderObject = createMeshRenderObject(values, state) renderObjects.push(_renderObject) - updated.next(updated.getValue() + 1) + updated.next(version++) }); } diff --git a/src/mol-repr/structure/complex-representation.ts b/src/mol-repr/structure/complex-representation.ts index c3b9051ac..816f84d4d 100644 --- a/src/mol-repr/structure/complex-representation.ts +++ b/src/mol-repr/structure/complex-representation.ts @@ -15,10 +15,11 @@ import { MarkerAction } from 'mol-geo/geometry/marker-data'; import { RepresentationContext, RepresentationParamsGetter } from 'mol-repr/representation'; import { Theme, createTheme } from 'mol-theme/theme'; import { ParamDefinition as PD } from 'mol-util/param-definition'; -import { BehaviorSubject } from 'rxjs'; +import { Subject } from 'rxjs'; export function ComplexRepresentation<P extends StructureParams>(label: string, getParams: RepresentationParamsGetter<Structure, P>, visualCtor: () => ComplexVisual<P>): StructureRepresentation<P> { - const updated = new BehaviorSubject(0) + let version = 0 + const updated = new Subject<number>() let visual: ComplexVisual<P> | undefined let _structure: Structure @@ -38,7 +39,7 @@ export function ComplexRepresentation<P extends StructureParams>(label: string, return Task.create('Creating or updating ComplexRepresentation', async runtime => { if (!visual) visual = visualCtor() await visual.createOrUpdate({ ...ctx, runtime }, _theme, _props, structure) - updated.next(updated.getValue() + 1) + updated.next(version++) }); } diff --git a/src/mol-repr/structure/units-representation.ts b/src/mol-repr/structure/units-representation.ts index aa525857d..84aed6c3d 100644 --- a/src/mol-repr/structure/units-representation.ts +++ b/src/mol-repr/structure/units-representation.ts @@ -17,7 +17,7 @@ import { MarkerAction } from 'mol-geo/geometry/marker-data'; import { Theme, createTheme } from 'mol-theme/theme'; import { ParamDefinition as PD } from 'mol-util/param-definition'; import { UnitKind, UnitKindOptions } from './visual/util/common'; -import { BehaviorSubject } from 'rxjs'; +import { Subject } from 'rxjs'; export const UnitsParams = { ...StructureParams, @@ -28,7 +28,8 @@ export type UnitsParams = typeof UnitsParams export interface UnitsVisual<P extends UnitsParams> extends Visual<StructureGroup, P> { } export function UnitsRepresentation<P extends UnitsParams>(label: string, getParams: RepresentationParamsGetter<Structure, P>, visualCtor: () => UnitsVisual<P>): StructureRepresentation<P> { - const updated = new BehaviorSubject(0) + let version = 0 + const updated = new Subject<number>() let visuals = new Map<number, { group: Unit.SymmetryGroup, visual: UnitsVisual<P> }>() let _structure: Structure @@ -120,7 +121,7 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, getPar } } if (structure) _structure = structure - updated.next(updated.getValue() + 1) + updated.next(version++) }); } @@ -169,7 +170,7 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, getPar }, get props() { return _props }, get params() { return _params }, - get updated() { return updated }, + updated, createOrUpdate, getLoci, mark, diff --git a/src/mol-repr/volume/representation.ts b/src/mol-repr/volume/representation.ts index 81e7d1ad0..075c02c8a 100644 --- a/src/mol-repr/volume/representation.ts +++ b/src/mol-repr/volume/representation.ts @@ -20,7 +20,7 @@ import { NullLocation } from 'mol-model/location'; import { VisualUpdateState } from 'mol-repr/util'; import { ValueCell } from 'mol-util'; import { Theme, createTheme } from 'mol-theme/theme'; -import { BehaviorSubject } from 'rxjs'; +import { Subject } from 'rxjs'; export interface VolumeVisual<P extends VolumeParams> extends Visual<VolumeData, P> { } @@ -143,7 +143,8 @@ export const VolumeParams = { export type VolumeParams = typeof VolumeParams export function VolumeRepresentation<P extends VolumeParams>(label: string, getParams: RepresentationParamsGetter<VolumeData, P>, visualCtor: (volume: VolumeData) => VolumeVisual<P>): VolumeRepresentation<P> { - const updated = new BehaviorSubject(0) + let version = 0 + const updated = new Subject<number>() let visual: VolumeVisual<P> let _volume: VolumeData @@ -177,7 +178,7 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, getP await visual.createOrUpdate({ ...ctx, runtime }, _theme, _props, volume) busy = false } - updated.next(updated.getValue() + 1) + updated.next(version++) }); } -- GitLab