Skip to content
Snippets Groups Projects
bootstrap.js 2.97 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jake Read's avatar
    Jake Read committed
    /*
    bootstrap.js
    
    client-side bootup of dataflow environment, and views into 
    
    Jake Read at the Center for Bits and Atoms
    (c) Massachusetts Institute of Technology 2019
    
    This work may be reproduced, modified, distributed, performed, and
    displayed for any purpose, but must acknowledge the squidworks and cuttlefish projects.
    Copyright is retained and must be preserved. The work is provided as is;
    no warranty is provided, and users accept all liability.
    */
    
    
    // IDDE sends msgs to manager, does display etc
    
    Jake Read's avatar
    Jake Read committed
    // starts with a native manager
    
    /* codename NROL39 aka cuttlefish */
    /* aka the teuthologist */
    
    
    // this is toplevel, UI is meta-hunk
    // we run loop where UI passes messages to bower manager
    // this is like the manager 'bootstrap' file ?
    
    Jake Read's avatar
    Jake Read committed
    
    
    Jake Read's avatar
    Jake Read committed
    'use strict'
    
    
    Jake Read's avatar
    Jake Read committed
    import Manager from './hunks/manager.js'
    
    Jake Read's avatar
    Jake Read committed
    import TLV from './view/vtoplevel.js'
    
    Jake Read's avatar
    Jake Read committed
    
    // this is the TL
    
    // but heirarchichally, we can slave views to managers ...
    // views push messages to managers ...
    
    Jake Read's avatar
    Jake Read committed
    
    // our invisible overlord
    let NROL = new Manager()
    
    Jake Read's avatar
    Jake Read committed
    // init sets type and ind,
    
    NROL.init()
    
    // this is going to sit in the outbuffer until the view resolves
    
    Jake Read's avatar
    Jake Read committed
    
    
    Jake Read's avatar
    Jake Read committed
    // want handles on this we think ?
    let view = {}
    let land
    
    
    // runs the loop inside of V8's loop: this way our interpreter is non-blocking
    // for other js async business
    
    Jake Read's avatar
    Jake Read committed
    function bootloop() {
    
      // js u wyldin ! (this is probably slow)
      try {
        NROL.loop()
      } catch (err) {
    
        console.error('ERR @ top of loop:', err)
    
    Jake Read's avatar
    Jake Read committed
        // write to the toplevel msgbox
        view.msgbox.write('ERR @ top of loop, see console, program halting!')
        console.error('loop halting, mgr bailing')
        return
    
      setTimeout(bootloop)
    
    Jake Read's avatar
    Jake Read committed
    }
    
    
      NROL.addHunk('view', 'tlview').then((vw) => {
    
        // console.log('ADDHUNK VIEW RESOLVES')
    
    Jake Read's avatar
    Jake Read committed
        // gotta git this
        view = vw
        $('#wrapper').get(0).append(view.dom)
    
    Jake Read's avatar
    Jake Read committed
        // itself
    
    Jake Read's avatar
    Jake Read committed
        view.onload()
    
    Jake Read's avatar
    Jake Read committed
        TLV(view)
    
    Jake Read's avatar
    Jake Read committed
        console.log("MTL'd")
    
        // outHunkIndex, outIndex, inHunkIndex, inIndex, debug
    
    Jake Read's avatar
    Jake Read committed
        NROL.addLink(1, 0, 0, 0, false)
        NROL.addLink(0, 0, 1, 0, false)
    
    Jake Read's avatar
    Jake Read committed
        setTimeout(() => {
    
    Jake Read's avatar
    Jake Read committed
          view.refresh().then(() => {
    
            // if you make links work properly (directionfull)
            // you can just pin view outputs to the left, collected,
    
    Jake Read's avatar
    Jake Read committed
            // and the rest should sort itself out
    
            //view.defs[0].floaters[0].fixTo(700,200)
    
    Jake Read's avatar
    Jake Read committed
            view.defs[1].unwrap()
            view.defs[1].floaters[0].fixTo(400, 100)
    
            //view.defs[1].floaters[1].fixTo(800, 300)
    
    Jake Read's avatar
    Jake Read committed
            // xtra
    
    Jake Read's avatar
    Jake Read committed
            /*
    
            view.patchset.mergePatch('lsocket').then(() => {
              let nlink = view.defs.find((cnd) => {
                return cnd.type === 'link'
              })
              nlink.floaters[0].fixTo(500,500)
              let nview = view.defs.find((cnd) =>{
                return (cnd.type === 'view' && cnd.name !== 'tlview')
    
              view.zoomExtents()
              nview.hunk.refresh()
            })
    
    Jake Read's avatar
    Jake Read committed
            */
    
    Jake Read's avatar
    Jake Read committed
          })
    
    Jake Read's avatar
    Jake Read committed
        }, 100)