Skip to content
Snippets Groups Projects
Commit d00ccdb3 authored by Alexander Rose's avatar Alexander Rose
Browse files

use Rx.Subject for repr.updated

parent e332f7cb
No related branches found
No related tags found
No related merge requests found
......@@ -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) => {
......
......@@ -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++)
});
}
......
......@@ -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++)
});
}
......
......@@ -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,
......
......@@ -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++)
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment