Skip to content
Snippets Groups Projects
Select Git revision
  • 2b5f62c42265e82e49372920a55bd7007943b803
  • master default protected
  • leo
  • dex
  • pendulum
  • apfelstruder
  • littlerascal
7 results

log_objects.js

Blame
  • Jake Read's avatar
    Jake Read authored
    7f0423a4
    History
    log_objects.js 1.08 KiB
    /*
    
    debugger ! log anything !
    
    */
    
    import { Hunkify, Input, Output, State } from '../hunks.js'
    
    export default function ObjectLogger() {
      Hunkify(this)
    
      // hmm...
      let tolog = this.input('reference', 'tolog')
    
      let prefix = this.state('string', 'prefix', 'LOG:')
      let logToConsole = this.state('boolean', 'console', true)
    
      this.dom = {}
    
      this.init = () => {
        this.dom = $('<div>').get(0)
      }
    
      this.onload = () => {
        //error here
        let text = $('<div>').addClass('txt').append('- >').get(0)
        $(this.dom).append(text)
      }
    
      this.loop = () => {
        // this will be called once every round turn
        // typically we check flow control first
        if (tolog.io()) {
          // an input is occupied, and the exit path is empty
          let raw = tolog.get()
          let stringRep
          if (Array.isArray(raw)) {
            stringRep = raw.join(', ')
          } else if (typeof raw === "boolean") {
            stringRep = raw.toString()
          }
          $(this.dom).children('.txt').html(stringRep)
          if (logToConsole.value === true) {
            console.log(this.ind, prefix.value, raw)
          }
        }
      }
    }