Skip to content
Snippets Groups Projects
reps.js 1.59 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jake Read's avatar
    Jake Read committed
    const JSUnit = require('./lib/jsunit.js')
    let isStateKey = JSUnit.isStateKey
    
    
    Jake Read's avatar
    Jake Read committed
    function makeRepFromModule(mdl) {
    
    Jake Read's avatar
    Jake Read committed
        // rep != mdl 
        // rep is rep of mdl 
    
    Jake Read's avatar
    Jake Read committed
        var rep = {
            description: {
                id: mdl.description.id,
                name: mdl.description.name,
                alt: mdl.description.alt,
                path: mdl.description.path
            }
        }
    
    
    Jake Read's avatar
    Jake Read committed
        // yikes tho, corner cases should be easier ... 
        if(mdl.description.isHardware){
            rep.description.isHardware = true
        }
    
        if(mdl.description.isLink){
            rep.description.isLink = true 
        }
    
    
        if(mdl.description.position){
            rep.description.position = mdl.description.position
        }
    
    
    Jake Read's avatar
    Jake Read committed
        // TODO: making rep. of input / output should be a f'n of that object ...
        // input, outputs, state objs should be known /sysobjects 
        // everything else is free play 
        rep.inputs = {}
        for (key in mdl.inputs) {
            rep.inputs[key] = {}
            rep.inputs[key].accepts = mdl.inputs[key].accepts
        }
    
        rep.outputs = {}
        for (key in mdl.outputs) {
            rep.outputs[key] = {}
            rep.outputs[key].emits = mdl.outputs[key].emits
            rep.outputs[key].calls = new Array()
            mdl.outputs[key].calls.forEach(function(inp) {
                var input = {
                    parentId: inp.parentId,
                    key: inp.key
                }
                rep.outputs[key].calls.push(input)
            })
        }
    
        rep.state = {}
        for(key in mdl.state){
            if(isStateKey(key)){
                rep.state[key] = mdl.state[key]
            }
        }
    
        return rep
    }
    
    module.exports = {
        makeFromModule: makeRepFromModule
    }