From 7b9dcac04883f6e40df9bfeb3ba9e5034ffbe1e2 Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Mon, 11 Feb 2019 13:51:54 +0100 Subject: [PATCH] mol-plugin: log tweaks --- src/mol-plugin/context.ts | 4 ++++ src/mol-plugin/ui/plugin.tsx | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mol-plugin/context.ts b/src/mol-plugin/context.ts index 0e524b8b3..46e16196c 100644 --- a/src/mol-plugin/context.ts +++ b/src/mol-plugin/context.ts @@ -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(); diff --git a/src/mol-plugin/ui/plugin.tsx b/src/mol-plugin/ui/plugin.tsx index 9805b9fa8..3304c9b79 100644 --- a/src/mol-plugin/ui/plugin.tsx +++ b/src/mol-plugin/ui/plugin.tsx @@ -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; -- GitLab