Select Git revision
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()
}
}
}