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

mol-plugin: PluginComponent refactoring

parent 0b12a4fa
Branches
Tags
No related merge requests found
......@@ -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
......@@ -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));
......
......@@ -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);
}
}
......
......@@ -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' });
}
}
......
......@@ -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>() });
}
}
......
......@@ -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>() });
}
}
......
......@@ -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' />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment