Browse Source

mol-plugin: log tweaks

David Sehnal 6 years ago
parent
commit
7b9dcac048
2 changed files with 6 additions and 3 deletions
  1. 4 0
      src/mol-plugin/context.ts
  2. 2 3
      src/mol-plugin/ui/plugin.tsx

+ 4 - 0
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();

+ 2 - 3
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;