From 8ee96cc8388c85c45277746d63f28d2241d0e7cb Mon Sep 17 00:00:00 2001 From: Jake <jake.read@cba.mit.edu> Date: Sun, 11 Nov 2018 15:54:55 -0500 Subject: [PATCH] delete module OK --- README.md | 5 +++++ lib/jsunit.js | 19 ++++++++++++++++++- programs.js | 13 +++++++++++++ views.js | 2 ++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 98cc470..b13fad7 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 1bc3075..dc4f50d 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 427ce16..f46a749 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 6ca1d5c..46f9079 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) { -- GitLab