Select Git revision
open_json.js
Jake Read authored
open_json.js 1.02 KiB
/*
open csv, setup outputs for fields (?)
*/
import {
Hunkify,
Input,
Output,
State
} from '../hunks.js'
export default function OpenJSON() {
Hunkify(this)
let outRef = new Output('reference', 'data', this)
this.outputs.push(outRef)
let refUpdated = false
let theRef = {}
let bumpState = new State('boolean', 'release', false)
this.states.push(bumpState)
bumpState.onChange = (value) => {
refUpdated = true
}
let readJSON = (file) => {
let reader = new FileReader()
reader.onload = (evt) => {
theRef = JSON.parse(evt.target.result)
// that's it,
refUpdated = true
}
reader.readAsText(file)
}
this.init = () => {
this.dom = $('<div>').get(0)
}
this.onload = () => {
let btn = $('<input type="file" accept=".json">').get(0)
$(btn).on('change', (evt) => {
readJSON(evt.target.files[0])
})
$(this.dom).append(btn)
}
this.loop = () => {
if(refUpdated && !outRef.io()){
outRef.put(theRef)
refUpdated = false
}
}
}