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'; ...@@ -15,7 +15,7 @@ import { getQualityProps } from './util';
import { ColorTheme } from 'mol-theme/color'; import { ColorTheme } from 'mol-theme/color';
import { SizeTheme } from 'mol-theme/size'; import { SizeTheme } from 'mol-theme/size';
import { Theme, ThemeRegistryContext } from 'mol-theme/theme'; import { Theme, ThemeRegistryContext } from 'mol-theme/theme';
import { BehaviorSubject } from 'rxjs'; import { Subject } from 'rxjs';
// export interface RepresentationProps { // export interface RepresentationProps {
// visuals?: string[] // visuals?: string[]
...@@ -80,7 +80,7 @@ export interface RepresentationContext { ...@@ -80,7 +80,7 @@ export interface RepresentationContext {
export { Representation } export { Representation }
interface Representation<D, P extends PD.Params = {}> { interface Representation<D, P extends PD.Params = {}> {
readonly label: string readonly label: string
readonly updated: BehaviorSubject<number> readonly updated: Subject<number>
readonly renderObjects: ReadonlyArray<RenderObject> readonly renderObjects: ReadonlyArray<RenderObject>
readonly props: Readonly<PD.Values<P>> readonly props: Readonly<PD.Values<P>>
readonly params: Readonly<P> readonly params: Readonly<P>
...@@ -94,7 +94,7 @@ interface Representation<D, P extends PD.Params = {}> { ...@@ -94,7 +94,7 @@ interface Representation<D, P extends PD.Params = {}> {
namespace Representation { namespace Representation {
export type Any = Representation<any> export type Any = Representation<any>
export const Empty: Any = { export const Empty: Any = {
label: '', renderObjects: [], props: {}, params: {}, updated: new BehaviorSubject(0), label: '', renderObjects: [], props: {}, params: {}, updated: new Subject(),
createOrUpdate: () => Task.constant('', undefined), createOrUpdate: () => Task.constant('', undefined),
getLoci: () => EmptyLoci, getLoci: () => EmptyLoci,
mark: () => false, mark: () => false,
...@@ -106,7 +106,8 @@ namespace Representation { ...@@ -106,7 +106,8 @@ namespace Representation {
export type Def<D, P extends PD.Params = {}> = { [k: string]: (getParams: RepresentationParamsGetter<D, P>) => Representation<any, P> } 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> { 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 currentParams: P
let currentProps: PD.Values<P> let currentProps: PD.Values<P>
...@@ -155,7 +156,7 @@ namespace Representation { ...@@ -155,7 +156,7 @@ namespace Representation {
await reprList[i].createOrUpdate(ctx, currentProps, currentData).runInContext(runtime) await reprList[i].createOrUpdate(ctx, currentProps, currentData).runInContext(runtime)
} }
} }
updated.next(updated.getValue() + 1) updated.next(version++)
}) })
}, },
getLoci: (pickingId: PickingId) => { getLoci: (pickingId: PickingId) => {
......
...@@ -19,7 +19,7 @@ import { PickingId } from 'mol-geo/geometry/picking'; ...@@ -19,7 +19,7 @@ import { PickingId } from 'mol-geo/geometry/picking';
import { MarkerAction, applyMarkerAction } from 'mol-geo/geometry/marker-data'; import { MarkerAction, applyMarkerAction } from 'mol-geo/geometry/marker-data';
import { LocationIterator } from 'mol-geo/util/location-iterator'; import { LocationIterator } from 'mol-geo/util/location-iterator';
import { createTheme } from 'mol-theme/theme'; import { createTheme } from 'mol-theme/theme';
import { BehaviorSubject } from 'rxjs'; import { Subject } from 'rxjs';
export interface ShapeRepresentation<P extends ShapeParams> extends Representation<Shape, P> { } export interface ShapeRepresentation<P extends ShapeParams> extends Representation<Shape, P> { }
...@@ -31,7 +31,8 @@ export const ShapeParams = { ...@@ -31,7 +31,8 @@ export const ShapeParams = {
export type ShapeParams = typeof ShapeParams export type ShapeParams = typeof ShapeParams
export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentation<P> { export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentation<P> {
const updated = new BehaviorSubject(0) let version = 0
const updated = new Subject<number>()
const renderObjects: RenderObject[] = [] const renderObjects: RenderObject[] = []
let _renderObject: MeshRenderObject | undefined let _renderObject: MeshRenderObject | undefined
let _shape: Shape let _shape: Shape
...@@ -57,7 +58,7 @@ export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentatio ...@@ -57,7 +58,7 @@ export function ShapeRepresentation<P extends ShapeParams>(): ShapeRepresentatio
_renderObject = createMeshRenderObject(values, state) _renderObject = createMeshRenderObject(values, state)
renderObjects.push(_renderObject) renderObjects.push(_renderObject)
updated.next(updated.getValue() + 1) updated.next(version++)
}); });
} }
......
...@@ -15,10 +15,11 @@ import { MarkerAction } from 'mol-geo/geometry/marker-data'; ...@@ -15,10 +15,11 @@ import { MarkerAction } from 'mol-geo/geometry/marker-data';
import { RepresentationContext, RepresentationParamsGetter } from 'mol-repr/representation'; import { RepresentationContext, RepresentationParamsGetter } from 'mol-repr/representation';
import { Theme, createTheme } from 'mol-theme/theme'; import { Theme, createTheme } from 'mol-theme/theme';
import { ParamDefinition as PD } from 'mol-util/param-definition'; 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> { 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 visual: ComplexVisual<P> | undefined
let _structure: Structure let _structure: Structure
...@@ -38,7 +39,7 @@ export function ComplexRepresentation<P extends StructureParams>(label: string, ...@@ -38,7 +39,7 @@ export function ComplexRepresentation<P extends StructureParams>(label: string,
return Task.create('Creating or updating ComplexRepresentation', async runtime => { return Task.create('Creating or updating ComplexRepresentation', async runtime => {
if (!visual) visual = visualCtor() if (!visual) visual = visualCtor()
await visual.createOrUpdate({ ...ctx, runtime }, _theme, _props, structure) 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'; ...@@ -17,7 +17,7 @@ import { MarkerAction } from 'mol-geo/geometry/marker-data';
import { Theme, createTheme } from 'mol-theme/theme'; import { Theme, createTheme } from 'mol-theme/theme';
import { ParamDefinition as PD } from 'mol-util/param-definition'; import { ParamDefinition as PD } from 'mol-util/param-definition';
import { UnitKind, UnitKindOptions } from './visual/util/common'; import { UnitKind, UnitKindOptions } from './visual/util/common';
import { BehaviorSubject } from 'rxjs'; import { Subject } from 'rxjs';
export const UnitsParams = { export const UnitsParams = {
...StructureParams, ...StructureParams,
...@@ -28,7 +28,8 @@ export type UnitsParams = typeof UnitsParams ...@@ -28,7 +28,8 @@ export type UnitsParams = typeof UnitsParams
export interface UnitsVisual<P extends UnitsParams> extends Visual<StructureGroup, P> { } 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> { 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 visuals = new Map<number, { group: Unit.SymmetryGroup, visual: UnitsVisual<P> }>()
let _structure: Structure let _structure: Structure
...@@ -120,7 +121,7 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, getPar ...@@ -120,7 +121,7 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, getPar
} }
} }
if (structure) _structure = structure 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 ...@@ -169,7 +170,7 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, getPar
}, },
get props() { return _props }, get props() { return _props },
get params() { return _params }, get params() { return _params },
get updated() { return updated }, updated,
createOrUpdate, createOrUpdate,
getLoci, getLoci,
mark, mark,
......
...@@ -20,7 +20,7 @@ import { NullLocation } from 'mol-model/location'; ...@@ -20,7 +20,7 @@ import { NullLocation } from 'mol-model/location';
import { VisualUpdateState } from 'mol-repr/util'; import { VisualUpdateState } from 'mol-repr/util';
import { ValueCell } from 'mol-util'; import { ValueCell } from 'mol-util';
import { Theme, createTheme } from 'mol-theme/theme'; 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> { } export interface VolumeVisual<P extends VolumeParams> extends Visual<VolumeData, P> { }
...@@ -143,7 +143,8 @@ export const VolumeParams = { ...@@ -143,7 +143,8 @@ export const VolumeParams = {
export type VolumeParams = typeof 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> { 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 visual: VolumeVisual<P>
let _volume: VolumeData let _volume: VolumeData
...@@ -177,7 +178,7 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, getP ...@@ -177,7 +178,7 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, getP
await visual.createOrUpdate({ ...ctx, runtime }, _theme, _props, volume) await visual.createOrUpdate({ ...ctx, runtime }, _theme, _props, volume)
busy = false 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