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

mol-plugin: log tweaks

parent c7e6fcce
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ import { CustomPropertyRegistry } from './util/custom-prop-registry';
import { VolumeRepresentationRegistry } from 'mol-repr/volume/registry';
import { PLUGIN_VERSION, PLUGIN_VERSION_DATE } from './version';
import { PluginLayout } from './layout';
import { List } from 'immutable';
export class PluginContext {
private disposed = false;
......@@ -103,6 +104,7 @@ export class PluginContext {
}
readonly log = {
entries: List<LogEntry>(),
entry: (e: LogEntry) => this.events.log.next(e),
error: (msg: string) => this.events.log.next(LogEntry.error(msg)),
message: (msg: string) => this.events.log.next(LogEntry.message(msg)),
......@@ -170,6 +172,8 @@ export class PluginContext {
}
constructor(public spec: PluginSpec) {
this.events.log.subscribe(e => this.log.entries = this.log.entries.push(e));
this.initBuiltInBehavior();
this.initBehaviors();
......
......@@ -116,15 +116,14 @@ export class Log extends PluginComponent<{}, { entries: List<LogEntry> }> {
private wrapper = React.createRef<HTMLDivElement>();
componentDidMount() {
// TODO: only show last 100 entries.
this.subscribe(this.plugin.events.log, e => this.setState({ entries: this.state.entries.push(e) }));
this.subscribe(this.plugin.events.log, () => this.setState({ entries: this.plugin.log.entries.takeLast(100).toList() }));
}
componentDidUpdate() {
this.scrollToBottom();
}
state = { entries: List<LogEntry>() };
state = { entries: this.plugin.log.entries.takeLast(100).toList() };
private scrollToBottom() {
const log = this.wrapper.current;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment