diff --git a/src/mol-plugin/context.ts b/src/mol-plugin/context.ts index 4aa5439e751bdaaa71e2319a4bab6a6b9b645ff8..5355bfc351a17b13970dac120d65dabd9e26bc08 100644 --- a/src/mol-plugin/context.ts +++ b/src/mol-plugin/context.ts @@ -7,10 +7,13 @@ import { State, StateTree, StateSelection, Transformer } from 'mol-state'; import Canvas3D from 'mol-canvas3d/canvas3d'; import { StateTransforms } from './state/transforms'; -import { Subject } from 'rxjs'; import { PluginStateObjects as SO } from './state/objects'; +import { RxEventHelper } from 'mol-util/rx-event-helper'; export class PluginContext { + private disposed = false; + private _events = new RxEventHelper(); + state = { data: State.create(new SO.Root({ label: 'Root' }, { })), // behaviour: State, @@ -19,7 +22,7 @@ export class PluginContext { // TODO: better events events = { - stateUpdated: new Subject<undefined>() + stateUpdated: this._events.create<undefined>() }; canvas3d: Canvas3D; @@ -36,6 +39,13 @@ export class PluginContext { } } + dispose() { + if (this.disposed) return; + this.canvas3d.dispose(); + this._events.dispose(); + this.disposed = true; + } + _test_createState(url: string) { const b = StateTree.build(this.state.data.tree); const newTree = b.toRoot() diff --git a/src/mol-util/rx-event-helper.ts b/src/mol-util/rx-event-helper.ts new file mode 100644 index 0000000000000000000000000000000000000000..4014f03a9f85d0311fd16fd071506e4972d68a85 --- /dev/null +++ b/src/mol-util/rx-event-helper.ts @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import { Subject } from 'rxjs'; + +export class RxEventHelper { + private _eventList: Subject<any>[] = []; + create<T>() { + const s = new Subject<T>(); + this._eventList.push(s); + return s; + } + dispose() { + for (const e of this._eventList) e.complete(); + } +} \ No newline at end of file