diff --git a/src/mol-plugin/component.ts b/src/mol-plugin/component.ts index 3d15fcb180e8967f2379ce6e5566ef9d1f53a5b1..b49f80c1bb2d219fe334bbbf9b093bf37e66fa1e 100644 --- a/src/mol-plugin/component.ts +++ b/src/mol-plugin/component.ts @@ -4,7 +4,6 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { PluginContext } from './context'; import { shallowMergeArray } from 'mol-util/object'; import { RxEventHelper } from 'mol-util/rx-event-helper'; @@ -35,7 +34,7 @@ export class PluginComponent<State> { if (this._ev) this._ev.dispose(); } - constructor(public context: PluginContext, initialState: State) { + constructor(initialState: State) { this._state = initialState; } } \ No newline at end of file diff --git a/src/mol-plugin/layout.ts b/src/mol-plugin/layout.ts index f41fd2c3a5274897173470929aec9a1b6bd9e8c3..63b8f19be005def858b246ed5d7e31317289b9e4 100644 --- a/src/mol-plugin/layout.ts +++ b/src/mol-plugin/layout.ts @@ -42,7 +42,6 @@ interface RootState { } export class PluginLayout extends PluginComponent<PluginLayoutStateProps> { - readonly events = { updated: this.ev() } @@ -176,8 +175,8 @@ export class PluginLayout extends PluginComponent<PluginLayoutStateProps> { } } - constructor(context: PluginContext) { - super(context, { ...PD.getDefaultValues(PluginLayoutStateParams), ...context.spec.initialLayout }); + constructor(private context: PluginContext) { + super({ ...PD.getDefaultValues(PluginLayoutStateParams), ...context.spec.initialLayout }); PluginCommands.Layout.Update.subscribe(context, e => this.updateProps(e.state)); diff --git a/src/mol-plugin/state.ts b/src/mol-plugin/state.ts index 60bc4a272685f88ec8b47ef92c936c885aef9aa3..86d08ec73f24dcea3fbc75af8dffdfbd1a01dfcc 100644 --- a/src/mol-plugin/state.ts +++ b/src/mol-plugin/state.ts @@ -22,8 +22,7 @@ class PluginState { readonly dataState: State; readonly behaviorState: State; readonly animation: PluginAnimationManager; - readonly cameraSnapshots: CameraSnapshotManager; - + readonly cameraSnapshots = new CameraSnapshotManager(); readonly snapshots = new PluginStateSnapshotManager(); readonly behavior = { @@ -89,7 +88,6 @@ class PluginState { this.behavior.currentObject.next(this.dataState.behaviors.currentObject.value); - this.cameraSnapshots = new CameraSnapshotManager(plugin); this.animation = new PluginAnimationManager(plugin); } } diff --git a/src/mol-plugin/state/animation/manager.ts b/src/mol-plugin/state/animation/manager.ts index 734ddf49a427a22ec8200153e735b19e7ec24fa0..fc83a7f448e6177c3c4582b7910afbbf901be3c0 100644 --- a/src/mol-plugin/state/animation/manager.ts +++ b/src/mol-plugin/state/animation/manager.ts @@ -162,8 +162,8 @@ class PluginAnimationManager extends PluginComponent<PluginAnimationManager.Stat requestAnimationFrame(this.animate); } - constructor(ctx: PluginContext) { - super(ctx, { params: { current: '' }, animationState: 'stopped' }); + constructor(private context: PluginContext) { + super({ params: { current: '' }, animationState: 'stopped' }); } } diff --git a/src/mol-plugin/state/camera.ts b/src/mol-plugin/state/camera.ts index 86709a7a190c39c212b74e476e694d8d9c15a921..830dbaf8de461f343944f16c1d1e1cfc21021579 100644 --- a/src/mol-plugin/state/camera.ts +++ b/src/mol-plugin/state/camera.ts @@ -8,7 +8,6 @@ import { Camera } from 'mol-canvas3d/camera'; import { OrderedMap } from 'immutable'; import { UUID } from 'mol-util'; import { PluginComponent } from 'mol-plugin/component'; -import { PluginContext } from 'mol-plugin/context'; export { CameraSnapshotManager } @@ -53,8 +52,8 @@ class CameraSnapshotManager extends PluginComponent<{ entries: OrderedMap<string this.events.changed.next(); } - constructor(ctx: PluginContext) { - super(ctx, { entries: OrderedMap<string, CameraSnapshotManager.Entry>() }); + constructor() { + super({ entries: OrderedMap<string, CameraSnapshotManager.Entry>() }); } } diff --git a/src/mol-plugin/state/snapshots.ts b/src/mol-plugin/state/snapshots.ts index 8d03ed5ae64a12902d462b635d2826350e5eae55..d9f4152d2f8ebd6a1e04916a0a498f6a0ee2d91f 100644 --- a/src/mol-plugin/state/snapshots.ts +++ b/src/mol-plugin/state/snapshots.ts @@ -6,44 +6,39 @@ import { OrderedMap } from 'immutable'; import { UUID } from 'mol-util'; -import { RxEventHelper } from 'mol-util/rx-event-helper'; import { PluginState } from '../state'; +import { PluginComponent } from 'mol-plugin/component'; export { PluginStateSnapshotManager } -class PluginStateSnapshotManager { - private ev = RxEventHelper.create(); - private _entries = OrderedMap<string, PluginStateSnapshotManager.Entry>().asMutable(); - +class PluginStateSnapshotManager extends PluginComponent<{ entries: OrderedMap<string, PluginStateSnapshotManager.Entry> }> { readonly events = { changed: this.ev() }; - get entries() { return this._entries; } - getEntry(id: string) { - return this._entries.get(id); + return this.state.entries.get(id); } remove(id: string) { - if (!this._entries.has(id)) return; - this._entries.delete(id); + if (!this.state.entries.has(id)) return; + this.updateState({ entries: this.state.entries.delete(id) }); this.events.changed.next(); } add(e: PluginStateSnapshotManager.Entry) { - this._entries.set(e.id, e); + this.updateState({ entries: this.state.entries.set(e.id, e) }); this.events.changed.next(); } clear() { - if (this._entries.size === 0) return; - this._entries = OrderedMap<string, PluginStateSnapshotManager.Entry>().asMutable(); + if (this.state.entries.size === 0) return; + this.updateState({ entries: OrderedMap<string, PluginStateSnapshotManager.Entry>() }); this.events.changed.next(); } - dispose() { - this.ev.dispose(); + constructor() { + super({ entries: OrderedMap<string, PluginStateSnapshotManager.Entry>() }); } } diff --git a/src/mol-plugin/ui/state.tsx b/src/mol-plugin/ui/state.tsx index ed8c45d00816052ee185a6a24a062ec02aef3fae..6e13eb42e85f0cd17e167e54713ea618840bee76 100644 --- a/src/mol-plugin/ui/state.tsx +++ b/src/mol-plugin/ui/state.tsx @@ -110,7 +110,7 @@ class LocalStateSnapshotList extends PluginUIComponent<{ }, { }> { render() { return <ul style={{ listStyle: 'none' }} className='msp-state-list'> - {this.plugin.state.snapshots.entries.valueSeq().map(e =><li key={e!.id}> + {this.plugin.state.snapshots.state.entries.valueSeq().map(e =><li key={e!.id}> <button className='msp-btn msp-btn-block msp-form-control' onClick={this.apply(e!.id)}>{e!.name || e!.timestamp} <small>{e!.description}</small></button> <button onClick={this.remove(e!.id)} className='msp-btn msp-btn-link msp-state-list-remove-button'> <span className='msp-icon msp-icon-remove' />