diff --git a/src/mol-plugin/context.ts b/src/mol-plugin/context.ts index 0e524b8b3af983b6965c34669dbeef6be423b8dd..46e16196c2021c5ded91ff4771aee709a2f38cb1 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 9805b9fa87d8d1216e2b9dc2fbcdbaf73826284f..3304c9b794edad9aae6d3e1c84cafa1db15ce8a6 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;