Select Git revision
plusequals.js

Jake Read authored
plusequals.js 875 B
/*
output += input
*/
import {
Hunkify,
Input,
Output,
State
} from '../hunks.js'
export default function PlusEquals() {
Hunkify(this)
let internalValue = 0
let hasUpdate = false
let resetLine = new Input('boolean', 'reset', this)
let input = new Input('number', 'plus', this)
this.inputs.push(resetLine, input)
let output = new Output('number', 'equals', this)
this.outputs.push(output)
let reset = new State('boolean', 'reset', false)
reset.onChange = (value) => {
internalValue = 0
}
this.states.push(reset)
this.init = () => {
//
}
this.loop = () => {
if(resetLine.io()){
resetLine.get()
internalValue = 0
}
if(input.io()){
internalValue += input.get()
hasUpdate = true
}
if(!output.io() && hasUpdate){
output.put(internalValue)
hasUpdate = false
}
}
}