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

LOG.md

Blame
  • save.js 1.06 KiB
    /*
    
    save object from reference, as JSON
    
    */
    
    import {
      Hunkify,
      Input,
      Output,
      State
    } from '../hunks.js'
    
    export default function Save(){
      Hunkify(this)
    
      let inobj = new Input("reference", "object", this)
      let intrig = new Input("boolean", "trigger", this)
      this.inputs.push(inobj, intrig)
      let savename = new State("string", "name", "datas")
      let svbutton = new State("boolean", "save", false)
      this.states.push(savename, svbutton)
    
      this.init = () => {
        //
      }
    
      let ourRef = {
        test: "item"
      }
    
      let dishit = () => {
        // serialize the thing
        let url = URL.createObjectURL(new Blob([JSON.stringify(ourRef, null, 2)], {
          type: "application/json"
        }))
        // hack to trigger the download,
        let anchor = $('<a>ok</a>').attr('href', url).attr('download', savename.value + '.json').get(0)
        $(document.body).append(anchor)
        anchor.click()
      }
    
      svbutton.onChange = (val) => {
        dishit()
      }
    
      this.loop = () => {
        if(inobj.io()){
          ourRef = inobj.get()
        }
        if(intrig.io()){
          intrig.get()
          dishit()
        }
      }
    }