diff --git a/README.md b/README.md index 98cc4709b48a1155b494faf872dde5d990b4ce1a..b13fad7eb7dccbbc067e7c1274c964807c8e6831 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,11 @@ This project serves the developement environment / api we use to write and repre - programs come in chunk-wise and get placed - programs are modules are heirarchical +## Questionable Moves + - module deletion seems unclean + - input / output objects should be able to unhook themselves: + - keep references of what-is-attached ? + ## WRT Representations OK diff --git a/lib/jsunit.js b/lib/jsunit.js index 1bc3075475210c7bddfe250c1a105db7f8f02f8f..dc4f50df8e73bb10307bbdf1d742cdf3dd37578b 100644 --- a/lib/jsunit.js +++ b/lib/jsunit.js @@ -39,6 +39,23 @@ function Output(type) { } } + output.removeAllLinks = function() { + this.calls = [] + } + + output.checkLinks = function(id){ + console.log('checking links', this) + for(index in this.calls){ + if(this.calls[index].parentId == id){ + console.log('popping null entry from', this.calls) + this.calls.splice(index, 1) + console.log('new record', this.calls) + } else { + // all good + } + } + } + output.emit = function(data) { if (this.calls.length == 0) { console.log('no inputs bound to this output') @@ -66,7 +83,7 @@ function State() { this.emitters[item]() } } - + return state } diff --git a/programs.js b/programs.js index 427ce16d1c92f9bba0586a0800613f8a60243222..f46a74909e6b52fa38d57993291da756238305de 100644 --- a/programs.js +++ b/programs.js @@ -85,6 +85,18 @@ function writeStateObject(mod, key) { }) } +function removeModuleFromProgram(program, id){ + // this simple? + delete program.modules[id] + + for(key in program.modules){ + var mdl = program.modules[key] + for(otKey in mdl.outputs){ + mdl.outputs[otKey].checkLinks(id) + } + } +} + /* EXTERNAL HOOKS @@ -201,5 +213,6 @@ module.exports = { open: openProgram, save: saveProgram, loadModuleFromSource: loadModuleFromSource, + removeModule: removeModuleFromProgram, assignSocket: assignSocket } \ No newline at end of file diff --git a/views.js b/views.js index 6ca1d5c515b15e360e01de36a93f791b649b86e0..46f90796660534bdc60070fe3e17c2a43ef04944 100644 --- a/views.js +++ b/views.js @@ -229,6 +229,8 @@ function uiRequestNewModule(data) { function uiRequestRemoveModule(data){ console.log('UI REQUEST TO REMOVE MODULE', data.id) + Programs.removeModule(program, data.id) + socketSend('restart', '') } function uiRequestStateChange(data) {