Skip to content
Snippets Groups Projects
Commit 602ca31e authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: PluginComponent refactoring

parent 0b12a4fa
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
*/ */
import { PluginContext } from './context';
import { shallowMergeArray } from 'mol-util/object'; import { shallowMergeArray } from 'mol-util/object';
import { RxEventHelper } from 'mol-util/rx-event-helper'; import { RxEventHelper } from 'mol-util/rx-event-helper';
...@@ -35,7 +34,7 @@ export class PluginComponent<State> { ...@@ -35,7 +34,7 @@ export class PluginComponent<State> {
if (this._ev) this._ev.dispose(); if (this._ev) this._ev.dispose();
} }
constructor(public context: PluginContext, initialState: State) { constructor(initialState: State) {
this._state = initialState; this._state = initialState;
} }
} }
\ No newline at end of file
...@@ -42,7 +42,6 @@ interface RootState { ...@@ -42,7 +42,6 @@ interface RootState {
} }
export class PluginLayout extends PluginComponent<PluginLayoutStateProps> { export class PluginLayout extends PluginComponent<PluginLayoutStateProps> {
readonly events = { readonly events = {
updated: this.ev() updated: this.ev()
} }
...@@ -176,8 +175,8 @@ export class PluginLayout extends PluginComponent<PluginLayoutStateProps> { ...@@ -176,8 +175,8 @@ export class PluginLayout extends PluginComponent<PluginLayoutStateProps> {
} }
} }
constructor(context: PluginContext) { constructor(private context: PluginContext) {
super(context, { ...PD.getDefaultValues(PluginLayoutStateParams), ...context.spec.initialLayout }); super({ ...PD.getDefaultValues(PluginLayoutStateParams), ...context.spec.initialLayout });
PluginCommands.Layout.Update.subscribe(context, e => this.updateProps(e.state)); PluginCommands.Layout.Update.subscribe(context, e => this.updateProps(e.state));
......
...@@ -22,8 +22,7 @@ class PluginState { ...@@ -22,8 +22,7 @@ class PluginState {
readonly dataState: State; readonly dataState: State;
readonly behaviorState: State; readonly behaviorState: State;
readonly animation: PluginAnimationManager; readonly animation: PluginAnimationManager;
readonly cameraSnapshots: CameraSnapshotManager; readonly cameraSnapshots = new CameraSnapshotManager();
readonly snapshots = new PluginStateSnapshotManager(); readonly snapshots = new PluginStateSnapshotManager();
readonly behavior = { readonly behavior = {
...@@ -89,7 +88,6 @@ class PluginState { ...@@ -89,7 +88,6 @@ class PluginState {
this.behavior.currentObject.next(this.dataState.behaviors.currentObject.value); this.behavior.currentObject.next(this.dataState.behaviors.currentObject.value);
this.cameraSnapshots = new CameraSnapshotManager(plugin);
this.animation = new PluginAnimationManager(plugin); this.animation = new PluginAnimationManager(plugin);
} }
} }
......
...@@ -162,8 +162,8 @@ class PluginAnimationManager extends PluginComponent<PluginAnimationManager.Stat ...@@ -162,8 +162,8 @@ class PluginAnimationManager extends PluginComponent<PluginAnimationManager.Stat
requestAnimationFrame(this.animate); requestAnimationFrame(this.animate);
} }
constructor(ctx: PluginContext) { constructor(private context: PluginContext) {
super(ctx, { params: { current: '' }, animationState: 'stopped' }); super({ params: { current: '' }, animationState: 'stopped' });
} }
} }
......
...@@ -8,7 +8,6 @@ import { Camera } from 'mol-canvas3d/camera'; ...@@ -8,7 +8,6 @@ import { Camera } from 'mol-canvas3d/camera';
import { OrderedMap } from 'immutable'; import { OrderedMap } from 'immutable';
import { UUID } from 'mol-util'; import { UUID } from 'mol-util';
import { PluginComponent } from 'mol-plugin/component'; import { PluginComponent } from 'mol-plugin/component';
import { PluginContext } from 'mol-plugin/context';
export { CameraSnapshotManager } export { CameraSnapshotManager }
...@@ -53,8 +52,8 @@ class CameraSnapshotManager extends PluginComponent<{ entries: OrderedMap<string ...@@ -53,8 +52,8 @@ class CameraSnapshotManager extends PluginComponent<{ entries: OrderedMap<string
this.events.changed.next(); this.events.changed.next();
} }
constructor(ctx: PluginContext) { constructor() {
super(ctx, { entries: OrderedMap<string, CameraSnapshotManager.Entry>() }); super({ entries: OrderedMap<string, CameraSnapshotManager.Entry>() });
} }
} }
......
...@@ -6,44 +6,39 @@ ...@@ -6,44 +6,39 @@
import { OrderedMap } from 'immutable'; import { OrderedMap } from 'immutable';
import { UUID } from 'mol-util'; import { UUID } from 'mol-util';
import { RxEventHelper } from 'mol-util/rx-event-helper';
import { PluginState } from '../state'; import { PluginState } from '../state';
import { PluginComponent } from 'mol-plugin/component';
export { PluginStateSnapshotManager } export { PluginStateSnapshotManager }
class PluginStateSnapshotManager { class PluginStateSnapshotManager extends PluginComponent<{ entries: OrderedMap<string, PluginStateSnapshotManager.Entry> }> {
private ev = RxEventHelper.create();
private _entries = OrderedMap<string, PluginStateSnapshotManager.Entry>().asMutable();
readonly events = { readonly events = {
changed: this.ev() changed: this.ev()
}; };
get entries() { return this._entries; }
getEntry(id: string) { getEntry(id: string) {
return this._entries.get(id); return this.state.entries.get(id);
} }
remove(id: string) { remove(id: string) {
if (!this._entries.has(id)) return; if (!this.state.entries.has(id)) return;
this._entries.delete(id); this.updateState({ entries: this.state.entries.delete(id) });
this.events.changed.next(); this.events.changed.next();
} }
add(e: PluginStateSnapshotManager.Entry) { add(e: PluginStateSnapshotManager.Entry) {
this._entries.set(e.id, e); this.updateState({ entries: this.state.entries.set(e.id, e) });
this.events.changed.next(); this.events.changed.next();
} }
clear() { clear() {
if (this._entries.size === 0) return; if (this.state.entries.size === 0) return;
this._entries = OrderedMap<string, PluginStateSnapshotManager.Entry>().asMutable(); this.updateState({ entries: OrderedMap<string, PluginStateSnapshotManager.Entry>() });
this.events.changed.next(); this.events.changed.next();
} }
dispose() { constructor() {
this.ev.dispose(); super({ entries: OrderedMap<string, PluginStateSnapshotManager.Entry>() });
} }
} }
......
...@@ -110,7 +110,7 @@ class LocalStateSnapshotList extends PluginUIComponent<{ }, { }> { ...@@ -110,7 +110,7 @@ class LocalStateSnapshotList extends PluginUIComponent<{ }, { }> {
render() { render() {
return <ul style={{ listStyle: 'none' }} className='msp-state-list'> 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 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'> <button onClick={this.remove(e!.id)} className='msp-btn msp-btn-link msp-state-list-remove-button'>
<span className='msp-icon msp-icon-remove' /> <span className='msp-icon msp-icon-remove' />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment