Просмотр исходного кода

Update raw html tag to self-update

We no longer need to call `write()`. Updating the `content` of the
`raw-html` tag before (or with) an `update()` event is sufficient.
Weiyi Lou 9 лет назад
Родитель
Сommit
d97ed83b34
1 измененных файлов с 10 добавлено и 13 удалено
  1. 10 13
      tags/terminal-ui.tag

+ 10 - 13
tags/terminal-ui.tag

@@ -8,8 +8,10 @@
   </style>
 
   /**
-   * Create a new shell with the class name given to the terminal-ui tag.
-   * The terminal-ui tag object passes events between the shell and the other tags.
+   * Create a new shell with the class name the terminal-ui tag was given.
+   * The terminal-ui tag itself is passed to this shell class.
+   * Being an Observable object, the terminal-ui tag transfers events between
+   * the shell and the other tags.
    */
   var shell = window[opts.shell] ? new window[opts.shell](this) : {}
   this.welcome = shell.welcome || opts.welcome
@@ -86,10 +88,7 @@
 
   this.on('mount', function() { this.command.focus() })
 
-  ev.on('prompt_set', function(text) {
-    self.prompt = text
-    self.tags.lhs.write(text)
-  })
+  ev.on('prompt_set', function(text) { self.prompt = text })
 
   ev.on('prompt_hide', function() { self.update({ prompt_visible: false }) })
 
@@ -108,18 +107,17 @@
 
   ev.on('context_swap', function(name) {
     name = name || 'default'
-    // Initialise a new context
+    // Initialise a new context if a given name does not already exist.
     if (!(name in self.contexts)) {
       self.contexts[name] = { visible: true, prompt: '', prompt_visible: true }
     }
-    // Save current values and load target context
+    // Save current values and load target context.
     ['visible', 'prompt', 'prompt_visible'].forEach(function(p) {
       self.contexts[self.current][p] = self[p]
       self[p] = self.contexts[name][p]
     })
     // Update the display.
     self.current = name
-    self.tags.lhs.write(self.prompt)
     if (self.visible) {
       self.command.focus()
     }
@@ -148,9 +146,8 @@
     raw-html { white-space: pre-wrap }
   </style>
 
-  // Set initial html using `content` option, and...
-  this.on('mount', function() { this.write(opts.content) })
+  this.on('mount', function() { this.write() })
+  this.on('update', function() { this.write() })
 
-  // Call `write()` manually to update the html.
-  write(text) { this.root.innerHTML = text }
+  write() { this.root.innerHTML = opts.content }
 </raw-html>