Select Git revision
-
Neil Gershenfeld authoredNeil Gershenfeld authored
manager.js 25.67 KiB
// heart of the fish ...
import {
Hunkify,
Input,
Output,
State
} from './hunks.js'
import {
TSET,
MK,
HK,
MSGS
} from '../typeset.js'
import GoGetter from '../gogetter.js'
function Manager() {
Hunkify(this, 'Manager')
// need this tool
let gg = new GoGetter
let msgsin = new Input('byteArray', 'msgs', this)
let msgsout = new Output('byteArray', 'msgs', this)
this.inputs.push(msgsin)
this.outputs.push(msgsout)
// we have hunks,
let hunks = new Array()
this.hunks = hunks
// we keep track of whether-or-not we have any connections ...
this.isConnectedTo = false
// debug flags
let verbose = false
let msgverbose = false
let addHunkVerbose = false
/* --------------------------- ---------------------------- */
/* ---------------------- BUILDING LIST ---------------------- */
/* --------------------------- ---------------------------- */
// for now, managers take callback paths to pipe data back through ?
let getListOfAvailableComponents = () => {
return new Promise((resolve, reject) => {
gg.recursivePathSearch('hunks/').then((list) => {
resolve(list)
}).catch((err) => {
reject(err)
})
})
}
/* --------------------------- ---------------------------- */
/* ------------------------ SERIALIZE ------------------------ */
/* --------------------------- ---------------------------- */
let serializeHunk = (hunk, bytes) => {
// write the hunk into this array
bytes.push(HK.IND)
// here, we're counting on the hunk containing its own address-within-the-array
// that gets set during an add, or decremented during a remove
MSGS.writeTo(bytes, hunk.ind, 'uint16')
// hunks are typed,
bytes.push(HK.TYPE)
MSGS.writeTo(bytes, hunk.type, 'string')
// an id, also, is nice, for optional human names ? maybe ?